Add stages to celery progress bar

This commit is contained in:
Quantum 2019-05-04 21:13:55 -07:00 committed by Guanzhong Chen
parent 1fb6f6662e
commit 32adce6189
4 changed files with 14 additions and 3 deletions

View File

@ -4,10 +4,11 @@ from django.utils.http import urlencode
class Progress:
def __init__(self, task, total):
def __init__(self, task, total, stage=None):
self.task = task
self._total = total
self._done = 0
self._stage = stage
def _update_state(self):
self.task.update_state(
@ -15,6 +16,7 @@ class Progress:
meta={
'done': self._done,
'total': self._total,
'stage': self._stage,
}
)

View File

@ -17,12 +17,13 @@ from judge.utils.views import short_circuit_middleware
def get_task_status(task_id):
result = AsyncResult(task_id)
info = result.result
if result.state == 'PROGRESS':
return {'code': 'PROGRESS', 'done': result.result['done'], 'total': result.result['total']}
return {'code': 'PROGRESS', 'done': info['done'], 'total': info['total'], 'stage': info['stage']}
elif result.state == 'SUCCESS':
return {'code': 'SUCCESS'}
elif result.state == 'FAILURE':
return {'code': 'FAILURE', 'error': str(result.result)}
return {'code': 'FAILURE', 'error': str(info)}
else:
return {'code': 'WORKING'}

View File

@ -125,6 +125,11 @@ body {
font-weight: 300;
}
.jumbotron .stage {
text-align: center;
font-weight: 300;
}
.jumbotron .progress {
background: #007bff;
position: relative;

View File

@ -11,6 +11,7 @@
var task_id = $jumbotron.attr('data-task-id');
var status = JSON.parse($jumbotron.attr('data-task-status'));
var redirect = $jumbotron.attr('data-redirect');
var $stage = $jumbotron.find('.stage');
var $progress = $jumbotron.find('.progress');
var $known = $jumbotron.find('.progress-known');
var $known_bar = $known.find('.progress-bar');
@ -40,6 +41,7 @@
$progress.filter('.progress-unknown').show();
break;
}
$stage.text(status.stage || '');
}
function need_ajax(status) {
@ -77,6 +79,7 @@
data-redirect="{{ redirect }}">
<img src="{{ static('icons/icon.svg') }}" class="icon" alt="DMOJ Icon">
<p class="action">{{ message }}</p>
<p class="stage"></p>
<div class="progress progress-known">
<div class="progress-bar" role="progressbar" aria-valuemin="0"></div>