mirror of
https://github.com/django-q2/django-q2.git
synced 2026-09-15 13:37:56 +08:00
rename config var to max_retries, remove attempt_count form admin , add admin ui customization to docs
This commit is contained in:
@@ -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."""
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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'}))
|
||||
|
||||
@@ -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],
|
||||
|
||||
@@ -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
|
||||
---------------
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user