In Celery, you can retry
any task in case of exception. You can do it like so:
@task(max_retries=5)
def div(a, b):
try:
return a / b
I searched this issue for a while, but found only this feature request.
I decide to write my own decorator for doing auto-retries:
def task_autoretry(*args_task, **kwargs_task):
def real_decorator(func):
@task(*args_task, **kwargs_task)
@functools.wraps(func)
def wrapper(*args, **kwargs):
try:
func(*args, **kwargs)
except kwargs_task.get('autoretry_on', Exception), exc:
wrapper.retry(exc=exc)
return wrapper
return real_decorator
With this decorator I can rewriter my previous task:
@task_autoretry(autoretry_on=ZeroDivisionError, max_retries=5)
def div(a, b):
return a / b