mirror of
https://github.com/DMOJ/online-judge.git
synced 2024-11-25 16:32:37 +08:00
Add stages to celery progress bar
This commit is contained in:
parent
1fb6f6662e
commit
32adce6189
@ -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,
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -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'}
|
||||
|
||||
|
@ -125,6 +125,11 @@ body {
|
||||
font-weight: 300;
|
||||
}
|
||||
|
||||
.jumbotron .stage {
|
||||
text-align: center;
|
||||
font-weight: 300;
|
||||
}
|
||||
|
||||
.jumbotron .progress {
|
||||
background: #007bff;
|
||||
position: relative;
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user