diff --git a/README.md b/README.md index c98d00e..b1426dd 100644 --- a/README.md +++ b/README.md @@ -168,6 +168,7 @@ The `initProgressBar` function takes an optional object of options. The followin | onDataError | function to call on a response that's not JSON or has invalid schema due to a programming error | onError | | onResult | function to call when returned non empty result | CeleryProgressBar.onResultDefault | | barColors | dictionary containing color values for various progress bar states. Colors that are not specified will defer to defaults | barColorsDefault | +| defaultMessages | dictionary containing default messages that can be overridden | see below | The `barColors` option allows you to customize the color of each progress bar state by passing a dictionary of key-value pairs of `state: #hexcode`. The defaults are shown below. @@ -178,6 +179,13 @@ The `barColors` option allows you to customize the color of each progress bar st | progress | #68a9ef | ![#68a9ef](https://placehold.it/15/68a9ef/000000?text=+) | | ignored | #7a7a7a | ![#7a7a7a](https://placehold.it/15/7a7a7a/000000?text=+) | +The `defaultMessages` option allows you to override some default messages in the UI. At the moment these are: + +| Message Id | When Shown | Default Value | +|-------|----------|:-------------:| +| waiting | Task is waiting to start | 'Waiting for task to start...' +| started | Task has started but reports no progress | 'Task started...' + # WebSocket Support Additionally, this library offers WebSocket support using [Django Channels](https://channels.readthedocs.io/en/latest/) diff --git a/celery_progress/backend.py b/celery_progress/backend.py index baba989..bf3cbd1 100644 --- a/celery_progress/backend.py +++ b/celery_progress/backend.py @@ -1,10 +1,12 @@ import datetime +import logging from abc import ABCMeta, abstractmethod from decimal import Decimal from celery.result import EagerResult, allow_join_result from celery.backends.base import DisabledBackend +logger = logging.getLogger(__name__) PROGRESS_STATE = 'PROGRESS' @@ -102,11 +104,12 @@ def get_info(self): 'progress': _get_unknown_progress(self.result.state), }) else: + logger.error('Task %s has unknown state %s with metadata %s', self.result.id, self.result.state, self.result.info) response.update({ 'complete': True, 'success': False, 'progress': _get_unknown_progress(self.result.state), - 'result': 'Unknown state {}'.format(str(self.result.info)), + 'result': 'Unknown state {}'.format(self.result.state), }) return response diff --git a/celery_progress/static/celery_progress/celery_progress.js b/celery_progress/static/celery_progress/celery_progress.js index 4fa178c..0a93845 100644 --- a/celery_progress/static/celery_progress/celery_progress.js +++ b/celery_progress/static/celery_progress/celery_progress.js @@ -29,12 +29,22 @@ class CeleryProgressBar { ignored: '#7a7a7a' } this.barColors = Object.assign({}, barColorsDefault, options.barColors); + + let defaultMessages = { + waiting: 'Waiting for task to start...', + started: 'Task started...', + } + this.messages = Object.assign({}, defaultMessages, options.defaultMessages); } onSuccessDefault(progressBarElement, progressBarMessageElement, result) { result = this.getMessageDetails(result); - progressBarElement.style.backgroundColor = this.barColors.success; - progressBarMessageElement.textContent = "Success! " + result; + if (progressBarElement) { + progressBarElement.style.backgroundColor = this.barColors.success; + } + if (progressBarMessageElement) { + progressBarMessageElement.textContent = "Success! " + result; + } } onResultDefault(resultElement, result) { @@ -75,9 +85,9 @@ class CeleryProgressBar { var description = progress.description || ""; if (progress.current == 0) { if (progress.pending === true) { - progressBarMessageElement.textContent = 'Waiting for task to start...'; + progressBarMessageElement.textContent = this.messages.waiting; } else { - progressBarMessageElement.textContent = 'Task started...'; + progressBarMessageElement.textContent = this.messages.started; } } else { progressBarMessageElement.textContent = progress.current + ' of ' + progress.total + ' processed. ' + description; diff --git a/celery_progress/urls.py b/celery_progress/urls.py index ff23848..fc3fcc6 100644 --- a/celery_progress/urls.py +++ b/celery_progress/urls.py @@ -1,7 +1,7 @@ -from django.conf.urls import url +from django.urls import re_path from . import views app_name = 'celery_progress' urlpatterns = [ - url(r'^(?P[\w-]+)/$', views.get_progress, name='task_status') + re_path(r'^(?P[\w-]+)/$', views.get_progress, name='task_status') ] diff --git a/setup.py b/setup.py index 893a1e3..eb0f101 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ setup( name='celery-progress', - version='0.0.14', + version='0.1.1', packages=find_packages(), include_package_data=True, license='MIT License', @@ -34,6 +34,9 @@ 'Programming Language :: Python', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', 'Topic :: Internet :: WWW/HTTP', 'Topic :: Internet :: WWW/HTTP :: Dynamic Content', ],