From 655f0aadb538c3a97ffda47f84a2b50f4cf4100b Mon Sep 17 00:00:00 2001 From: Tim O'Meara Date: Thu, 13 Aug 2020 11:58:00 -0500 Subject: [PATCH] rename config var to max_retries, remove attempt_count form admin , add admin ui customization to docs --- django_q/admin.py | 2 +- django_q/cluster.py | 2 +- django_q/conf.py | 2 +- django_q/tests/test_admin.py | 6 ++---- django_q/tests/test_cluster.py | 2 +- docs/admin.rst | 23 +++++++++++++++++++++++ docs/configure.rst | 6 +++--- 7 files changed, 32 insertions(+), 11 deletions(-) diff --git a/django_q/admin.py b/django_q/admin.py index f40118e..a7484ce 100644 --- a/django_q/admin.py +++ b/django_q/admin.py @@ -43,7 +43,7 @@ retry_failed.short_description = _("Resubmit selected tasks to queue") class FailAdmin(admin.ModelAdmin): """model admin for failed tasks.""" - list_display = ("name", "func", "started", "stopped", "short_result", "attempt_count") + list_display = ("name", "func", "started", "stopped", "short_result") def has_add_permission(self, request): """Don't allow adds.""" diff --git a/django_q/cluster.py b/django_q/cluster.py index d8e6f27..1d55663 100644 --- a/django_q/cluster.py +++ b/django_q/cluster.py @@ -481,7 +481,7 @@ def save_task(task, broker: Broker): existing_task.attempt_count = existing_task.attempt_count + 1 existing_task.save() - if 0 < Conf.ATTEMPT_COUNT == existing_task.attempt_count: + if Conf.MAX_ATTEMPTS > 0 and existing_task.attempt_count >= Conf.MAX_ATTEMPTS: broker.acknowledge(task['ack_id']) else: diff --git a/django_q/conf.py b/django_q/conf.py index 964364f..ba7e370 100644 --- a/django_q/conf.py +++ b/django_q/conf.py @@ -165,7 +165,7 @@ class Conf: ERROR_REPORTER = conf.get("error_reporter", {}) # Optional attempt count. set to 0 for infinite attempts - ATTEMPT_COUNT = conf.get('attempt_count', 0) + MAX_ATTEMPTS = conf.get('max_attempts', 0) # OSX doesn't implement qsize because of missing sem_getvalue() try: diff --git a/django_q/tests/test_admin.py b/django_q/tests/test_admin.py index 5dc8880..52e8d41 100644 --- a/django_q/tests/test_admin.py +++ b/django_q/tests/test_admin.py @@ -21,8 +21,7 @@ def test_admin_views(admin_client, monkeypatch): func='test.fail', started=timezone.now(), stopped=timezone.now(), - success=False, - attempt_count=1) + success=False) tag = uuid() t = Task.objects.create( id=tag[1], @@ -30,8 +29,7 @@ def test_admin_views(admin_client, monkeypatch): func='test.success', started=timezone.now(), stopped=timezone.now(), - success=True, - attempt_count=1) + success=True) q = OrmQ.objects.create( key='test', payload=SignedPackage.dumps({'id': 1, 'func': 'test', 'name': 'test'})) diff --git a/django_q/tests/test_cluster.py b/django_q/tests/test_cluster.py index efb7089..a6fd742 100644 --- a/django_q/tests/test_cluster.py +++ b/django_q/tests/test_cluster.py @@ -399,7 +399,7 @@ def test_bad_secret(broker, monkeypatch): @pytest.mark.django_db def test_attempt_count(broker, monkeypatch): - monkeypatch.setattr(Conf, 'ATTEMPT_COUNT', 3) + monkeypatch.setattr(Conf, 'MAX_ATTEMPTS', 3) tag = uuid() task = {'id': tag[1], 'name': tag[0], diff --git a/docs/admin.rst b/docs/admin.rst index 9eace11..aad6913 100644 --- a/docs/admin.rst +++ b/docs/admin.rst @@ -33,6 +33,29 @@ You can resubmit a failed task back to the queue using the admins action menu. Uses the :class:`Failure` proxy model + + +Customize the admin UI by creating your own ``admin.ModelAdmin`` class and use ``admin.site.unregister`` and ``admin.site.register`` to replace the default +for example: + +.. code-block:: python + from django_q import models as q_models + from django_q import admin as q_admin + + admin.site.unregister([q_models.Failure]) + @admin.register(q_models.Failure) + class ChildClassAdmin(q_admin.FailAdmin): + list_display = ( + 'name', + 'func', + 'result', + 'started', + # add attempt_count to list_display + 'attempt_count' + ) + + + Scheduled tasks --------------- diff --git a/docs/configure.rst b/docs/configure.rst index afc6aa0..18e8d42 100644 --- a/docs/configure.rst +++ b/docs/configure.rst @@ -76,12 +76,12 @@ ack_failures When set to ``True``, also acknowledge unsuccessful tasks. This causes failed tasks to be considered as successful deliveries, thereby removing them from the task queue. Can also be set per-task by passing the ``ack_failure`` option to :func:`async_task`. Defaults to ``False``. -.. attempt_count: +.. _max_attempts: -attempt_count +max_attempts ~~~~~~~~~~~~~ -Limit the number of retries for failed tasks. Set to 0 for infinite retries. Defaults to 0 +Limit the number of retry attempts for failed tasks. Set to 0 for infinite retries. Defaults to 0 .. _retry: