Skip to content

Commit

Permalink
rename config var to max_retries, remove attempt_count form admin , a…
Browse files Browse the repository at this point in the history
…dd admin ui customization to docs
  • Loading branch information
timomeara committed Aug 13, 2020
1 parent 991cca5 commit 655f0aa
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 11 deletions.
2 changes: 1 addition & 1 deletion django_q/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def retry_failed(FailAdmin, request, queryset):
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."""
Expand Down
2 changes: 1 addition & 1 deletion django_q/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion django_q/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 2 additions & 4 deletions django_q/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,15 @@ 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],
name=tag[0],
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'}))
Expand Down
2 changes: 1 addition & 1 deletion django_q/tests/test_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
23 changes: 23 additions & 0 deletions docs/admin.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
---------------

Expand Down
6 changes: 3 additions & 3 deletions docs/configure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 655f0aa

Please sign in to comment.