Celery Task Retry With Backoff

Configure Celery tasks with retry backoff jitter and max attempts for resilient async jobs.

PythonResilience

Code

snippet
from celery import Celery
from celery.exceptions import Retry
import random

app = Celery('tasks', broker='redis://localhost:6379')

@app.task(bind=True, max_retries=5)
def process_data(self, payload):
    try:
        return do_work(payload)
    except Exception as exc:
        raise self.retry(
            exc=exc,
            countdown=int(2 ** self.request.retries * (1 + random.random())),
        )