Hi Dave, Please find updated patch.
-- *Harshal Dhumal* *Sr. Software Engineer* EnterpriseDB India: http://www.enterprisedb.com The Enterprise PostgreSQL Company On Mon, Nov 27, 2017 at 5:28 PM, Dave Page <dp...@pgadmin.org> wrote: > Hi > > On Mon, Nov 27, 2017 at 11:23 AM, Harshal Dhumal < > harshal.dhu...@enterprisedb.com> wrote: > >> 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. >> > > Seems to work nicely, except that the text scrolls out of view almost > immediately. Can you fix it to jump to the end of the text when more is > appended please? > > Fixed. > Thanks. > > -- > Dave Page > Blog: http://pgsnake.blogspot.com > Twitter: @pgsnake > > EnterpriseDB UK: 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..be4ac15 100644 --- a/web/pgadmin/misc/bgprocess/static/js/bgprocess.js +++ b/web/pgadmin/misc/bgprocess/static/js/bgprocess.js @@ -159,8 +159,12 @@ define('misc.bgprocess', [ while (ie < err.length) { res.push('<li class="pg-bg-res-err">' + escapeHTML(err[ie++][1]) + '</li>'); } + if (res.length) { self.logs.append(res.join('')); + setTimeout(function() { + self.logs[0].scrollTop = self.logs[0].scrollHeight; + }); } if (self.stime) { @@ -301,9 +305,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) } @@ -336,7 +347,9 @@ define('misc.bgprocess', [ if (is_new) { // set logs $logs.html(self.logs); - + setTimeout(function() { + self.logs[0].scrollTop = self.logs[0].scrollHeight; + }); // set bgprocess detailed description $header.find('.bg-detailed-desc').html(self.detailed_desc); }