Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show task started even if it doesn't update progress #48

Merged
merged 2 commits into from
Sep 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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