[Django]-Retrying tasks with Django-Celery – Django/Celery

17πŸ‘

βœ…

The task needs to accept keyword arguments, they are used to pass information amongst other about the retry count. I think the code should look like this:

from celery.decorators import task

@task()
def add(x, y, **kwargs):
    if not x or not y:
        try:
            raise Exception("test error")
        except Exception, e:
            add.retry(args=[x, y], exc=e, countdown=30, kwargs=kwargs)
    return x+y

**kwargs need to be added to the signature of the add function, and passed as kwargs=kwargs when calling retry.

Note: this style was deprecated with the release of celery 2.2.

28πŸ‘

You can set your retry parameters in the decorator:

@task(default_retry_delay=5 * 60, max_retries=12)
def foo(bar):
  try:
      ...
  except Exception, exc:
      raise foo.retry(exc=exc)
πŸ‘€dalore

Leave a comment