Hi,

Please find attached patch to fix RM2811

Issue was caused due to assumption made when current position in log file
while reading it reaches to last line then
we were assuming process is finished. However this is not the case.
Background process may be busy performing
some other task and logs might not be logged to file immediately. So we
should also check process exit code along
with above condition.

Apart from above this patch also includes minor fix related to status text
colour.

--
*Harshal Dhumal*
*Sr. Software Engineer*

EnterpriseDB India: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
diff --git a/web/pgadmin/misc/bgprocess/processes.py b/web/pgadmin/misc/bgprocess/processes.py
index 0b94775..209c2a1 100644
--- a/web/pgadmin/misc/bgprocess/processes.py
+++ b/web/pgadmin/misc/bgprocess/processes.py
@@ -365,7 +365,7 @@ class BatchProcess(object):
         if enc is None or enc == 'ascii':
             enc = 'utf-8'
 
-        def read_log(logfile, log, pos, ctime):
+        def read_log(logfile, log, pos, ctime, ecode=None):
             completed = True
             idx = 0
             c = re.compile(r"(\d+),(.*$)")
@@ -376,6 +376,9 @@ class BatchProcess(object):
             with open(logfile, 'rb') as f:
                 eofs = os.fstat(f.fileno()).st_size
                 f.seek(pos, 0)
+                if pos == eofs and ecode is None:
+                    completed = False
+
                 while pos < eofs:
                     idx += 1
                     line = f.readline()
@@ -394,15 +397,12 @@ class BatchProcess(object):
                         completed = False
                         break
                     if pos == eofs:
-                        completed = True
+                        if ecode is None:
+                            completed = False
                         break
 
             return pos, completed
 
-        if process_output:
-            out, out_completed = read_log(self.stdout, stdout, out, ctime)
-            err, err_completed = read_log(self.stderr, stderr, err, ctime)
-
         j = Process.query.filter_by(
             pid=self.id, user_id=current_user.id
         ).first()
@@ -423,11 +423,11 @@ class BatchProcess(object):
 
                 execution_time = (etime - stime).total_seconds()
 
-            if process_output and self.ecode is not None and (
-                len(stdout) + len(stderr) < 1024
-            ):
-                out, out_completed = read_log(self.stdout, stdout, out, ctime)
-                err, err_completed = read_log(self.stderr, stderr, err, ctime)
+            if process_output:
+                out, out_completed = read_log(self.stdout, stdout, out, ctime,
+                                              self.ecode)
+                err, err_completed = read_log(self.stderr, stderr, err, ctime,
+                                              self.ecode)
         else:
             out_completed = err_completed = False
 
diff --git a/web/pgadmin/misc/bgprocess/static/js/bgprocess.js b/web/pgadmin/misc/bgprocess/static/js/bgprocess.js
index a4506b5..bc61733 100644
--- a/web/pgadmin/misc/bgprocess/static/js/bgprocess.js
+++ b/web/pgadmin/misc/bgprocess/static/js/bgprocess.js
@@ -301,9 +301,16 @@ define('misc.bgprocess', [
           ).append(
             $('<span></span>').text(' ' + gettext('seconds'))
           );
-          self.container.find('.pg-bg-status').empty().append(
+          var $status_bar = $(self.container.find('.pg-bg-status'));
+          $status_bar.empty().append(
             self.curr_status
           );
+
+          if (self.exit_code === 0) {
+            $status_bar.addClass('bg-success');
+          } else if (self.exit_code == 1){
+            $status_bar.addClass('bg-failed');
+          }
         } else {
           self.show_detailed_view.apply(self)
         }

Reply via email to