Skip to content

Commit

Permalink
Merge pull request #48 from OmarWKH/no-progress-task
Browse files Browse the repository at this point in the history
Show task started even if it doesn't update progress
  • Loading branch information
czue authored Sep 8, 2020
2 parents 314e232 + 277a3f1 commit af964fe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
9 changes: 6 additions & 3 deletions celery_progress/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def set_progress(self, current, total, description=""):
self.task.update_state(
state=PROGRESS_STATE,
meta={
'pending': False,
'current': current,
'total': total,
'percent': percent,
Expand All @@ -53,6 +54,7 @@ def stop_task(self, current, total, exc):
self.task.update_state(
state='FAILURE',
meta={
'pending': False,
'current': current,
'total': total,
'percent': 100.0,
Expand Down Expand Up @@ -88,22 +90,23 @@ def get_info(self):
return {
'complete': False,
'success': None,
'progress': _get_unknown_progress(),
'progress': _get_unknown_progress(self.result.state),
}
return self.result.info


def _get_completed_progress():
return {
'pending': False,
'current': 100,
'total': 100,
'percent': 100,
}


def _get_unknown_progress():
def _get_unknown_progress(state):
return {
'pending': True,
'pending': state == 'PENDING',
'current': 0,
'total': 100,
'percent': 0,
Expand Down
10 changes: 7 additions & 3 deletions celery_progress/static/celery_progress/celery_progress.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,14 @@ class CeleryProgressBar {
progressBarElement.style.backgroundColor = '#68a9ef';
progressBarElement.style.width = progress.percent + "%";
var description = progress.description || "";
if (progress.current == 0 && progress.pending) {
progressBarMessageElement.textContent = 'Waiting for task to start...'
if (progress.current == 0) {
if (progress.pending === true) {
progressBarMessageElement.textContent = 'Waiting for task to start...';
} else {
progressBarMessageElement.textContent = 'Task started...';
}
} else {
progressBarMessageElement.textContent = progress.current + ' of ' + progress.total + ' processed. ' + description;
progressBarMessageElement.textContent = progress.current + ' of ' + progress.total + ' processed. ' + description;
}
}

Expand Down

0 comments on commit af964fe

Please sign in to comment.