From e93b0962ddfe5a6522a0b812f0c662ba94c200e5 Mon Sep 17 00:00:00 2001 From: Omar Khashoggi Date: Mon, 7 Sep 2020 20:13:25 +0300 Subject: [PATCH 1/2] progress.pending indicates if a task was started --- celery_progress/backend.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/celery_progress/backend.py b/celery_progress/backend.py index be5228b..cf923af 100644 --- a/celery_progress/backend.py +++ b/celery_progress/backend.py @@ -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, @@ -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, @@ -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, From 277a3f144a1946990bb4b685d420ea66d2b923e8 Mon Sep 17 00:00:00 2001 From: Omar Khashoggi Date: Mon, 7 Sep 2020 20:13:56 +0300 Subject: [PATCH 2/2] show a different message for a started task with no progress --- .../static/celery_progress/celery_progress.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/celery_progress/static/celery_progress/celery_progress.js b/celery_progress/static/celery_progress/celery_progress.js index 140c29f..509af38 100644 --- a/celery_progress/static/celery_progress/celery_progress.js +++ b/celery_progress/static/celery_progress/celery_progress.js @@ -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; } }