Преглед изворни кода

HUE-1391 [jobbrowser] last line repeated when executing oozie workflow

Improved json retrieval (timeout instead of interval)
Fixed a problem with new lines
Enrico Berti пре 12 година
родитељ
комит
52d14b7

+ 2 - 12
apps/jobbrowser/src/jobbrowser/templates/attempt_logs.mako

@@ -159,13 +159,6 @@ ${ commonheader(_('Task Attempt: %(attemptId)s') % dict(attemptId=attempt.attemp
     });
 
     refreshLogs();
-    var logsRefreshInterval = window.setInterval(function () {
-      refreshLogs();
-    }, 1000);
-
-    $(document).on("stopLogsRefresh", function () {
-      window.clearInterval(logsRefreshInterval);
-    });
 
     initLogsElement($("#logsDiagnostic pre"));
     initLogsElement($("#logsStdOut pre"));
@@ -185,13 +178,10 @@ ${ commonheader(_('Task Attempt: %(attemptId)s') % dict(attemptId=attempt.attemp
           appendAndScroll($("#logsStdErr pre"), log_stderr);
           appendAndScroll($("#logsSysLog pre"), log_syslog);
 
-          if (!data.isRunning) {
-            $(document).trigger("stopLogsRefresh");
+          if (data.isRunning) {
+            window.setTimeout(refreshLogs, 1000);
           }
         }
-        else {
-          $(document).trigger("stopLogsRefresh");
-        }
       });
     }
 

+ 16 - 17
apps/jobbrowser/src/jobbrowser/templates/job_attempt_logs.mako

@@ -107,45 +107,44 @@ ${ commonheader(_('Job Attempt: %(attempt_index)s') % {'attempt_index': attempt_
     // From 15s to less than 5s display time with async
 
     refreshLogs();
-    var logsRefreshInterval = window.setInterval(function () {
-      refreshLogs();
-    }, 5000);
-
-    $(document).on("stopLogsRefresh", function () {
-      window.clearInterval(logsRefreshInterval);
-    });
 
     initLogsElement($("#syslog-container"));
     initLogsElement($("#stdout-container"));
     initLogsElement($("#stderr-container"));
 
-    function refreshLogs() {
+    function refreshSyslogs() {
       $.getJSON("${ url("jobbrowser.views.job_attempt_logs_json", job=job.jobId, attempt_index=attempt_index, name='syslog', offset=0) }", function (data) {
         if (data && data.log) {
           appendAndScroll($("#syslog-container"), data.log);
-        }
-        else {
-          $(document).trigger("stopLogsRefresh");
+          window.setTimeout(refreshSyslogs, 5000);
         }
       });
+    }
+
+    function refreshStdout() {
       $.getJSON("${ url("jobbrowser.views.job_attempt_logs_json", job=job.jobId, attempt_index=attempt_index, name='stdout', offset=0) }", function (data) {
         if (data && data.log) {
           appendAndScroll($("#stdout-container"), data.log);
-        }
-        else {
-          $(document).trigger("stopLogsRefresh");
+          window.setTimeout(refreshStdout, 5000);
         }
       });
+    }
+
+    function refreshStderr() {
       $.getJSON("${ url("jobbrowser.views.job_attempt_logs_json", job=job.jobId, attempt_index=attempt_index, name='stderr', offset=0) }", function (data) {
         if (data && data.log) {
           appendAndScroll($("#stderr-container"), data.log);
-        }
-        else {
-          $(document).trigger("stopLogsRefresh");
+          window.setTimeout(refreshStderr, 5000);
         }
       });
     }
 
+    function refreshLogs() {
+      refreshSyslogs();
+      refreshStdout();
+      refreshStderr();
+    }
+
     $(document).on("resized", function () {
       resizeLogs($("#syslog-container"));
       resizeLogs($("#stdout-container"));

+ 3 - 1
apps/jobbrowser/static/js/utils.js

@@ -24,7 +24,9 @@ function initLogsElement(element) {
 
 function appendAndScroll(element, logs) {
   var newLines = logs.split("\n").slice(element.text().split("\n").length);
-  element.text(element.text() + newLines.join("\n"));
+  if (newLines.length > 0) {
+    element.text(element.text() + newLines.join("\n") + "\n");
+  }
   if (element.data("logsAtEnd")) {
     element.scrollTop(element[0].scrollHeight - element.height());
   }