Display process output as it happens. Fixes #2811
parent
80c4a3fb1a
commit
7db7da5b0e
|
@ -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
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue