H
H
herypank2022-04-18 18:36:55
Python
herypank, 2022-04-18 18:36:55

How to make celery retry through passing arguments?

I have a task to run celery tasks with different retry arguments, who can tell me how this can be implemented?

Here is a sample of the code to test:

from celery import Celery

app = Celery('tasks', broker='amqp://[email protected]//')

import celery



class RetryCeleryWorker(celery.Task):
    autoretry_for = (Exception,)
    retry_backoff = True
    retry_backoff_max = 700
    retry_jitter = False

@app.task(base=RetryCeleryWorker)
def add():
    print('add starting')
    0/0
    print('add finish')


I found such a solution, but it does not work

https://lifesaver.codes/answer/delay-and-apply-asy...

I want the task to start like this

from tasks import add, app, RetryCeleryWorker


add.apply_async(retry=True, retry_policy={
    'max_retries': 5,
})


but for some reason max_retries and other arguments do not get into celery or are not read.

The idea is that if I pass something, then it is applied as in the celery attributes, and if I do not pass, then the default ones are used in the

upd class. found this, it looks like you need to write your own crutch https://github.com/celery/celery/issues/2457

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question