rename config var to max_retries, remove attempt_count form admin , add admin ui customization to docs

This commit is contained in:
Tim O'Meara
2020-08-13 11:58:00 -05:00
parent 991cca5844
commit 655f0aadb5
7 changed files with 32 additions and 11 deletions
+1 -1
View File
@@ -43,7 +43,7 @@ retry_failed.short_description = _("Resubmit selected tasks to queue")
class FailAdmin(admin.ModelAdmin): class FailAdmin(admin.ModelAdmin):
"""model admin for failed tasks.""" """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): def has_add_permission(self, request):
"""Don't allow adds.""" """Don't allow adds."""
+1 -1
View File
@@ -481,7 +481,7 @@ def save_task(task, broker: Broker):
existing_task.attempt_count = existing_task.attempt_count + 1 existing_task.attempt_count = existing_task.attempt_count + 1
existing_task.save() 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']) broker.acknowledge(task['ack_id'])
else: else:
+1 -1
View File
@@ -165,7 +165,7 @@ class Conf:
ERROR_REPORTER = conf.get("error_reporter", {}) ERROR_REPORTER = conf.get("error_reporter", {})
# Optional attempt count. set to 0 for infinite attempts # 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() # OSX doesn't implement qsize because of missing sem_getvalue()
try: try:
+2 -4
View File
@@ -21,8 +21,7 @@ def test_admin_views(admin_client, monkeypatch):
func='test.fail', func='test.fail',
started=timezone.now(), started=timezone.now(),
stopped=timezone.now(), stopped=timezone.now(),
success=False, success=False)
attempt_count=1)
tag = uuid() tag = uuid()
t = Task.objects.create( t = Task.objects.create(
id=tag[1], id=tag[1],
@@ -30,8 +29,7 @@ def test_admin_views(admin_client, monkeypatch):
func='test.success', func='test.success',
started=timezone.now(), started=timezone.now(),
stopped=timezone.now(), stopped=timezone.now(),
success=True, success=True)
attempt_count=1)
q = OrmQ.objects.create( q = OrmQ.objects.create(
key='test', key='test',
payload=SignedPackage.dumps({'id': 1, 'func': 'test', 'name': 'test'})) payload=SignedPackage.dumps({'id': 1, 'func': 'test', 'name': 'test'}))
+1 -1
View File
@@ -399,7 +399,7 @@ def test_bad_secret(broker, monkeypatch):
@pytest.mark.django_db @pytest.mark.django_db
def test_attempt_count(broker, monkeypatch): def test_attempt_count(broker, monkeypatch):
monkeypatch.setattr(Conf, 'ATTEMPT_COUNT', 3) monkeypatch.setattr(Conf, 'MAX_ATTEMPTS', 3)
tag = uuid() tag = uuid()
task = {'id': tag[1], task = {'id': tag[1],
'name': tag[0], 'name': tag[0],
+23
View File
@@ -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 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 Scheduled tasks
--------------- ---------------
+3 -3
View File
@@ -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``. 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: .. _retry: