S
S
Strohmann2019-04-22 08:22:37
Celery
Strohmann, 2019-04-22 08:22:37

Is it possible to call a task in a chain with a parameterized max_retries option?

You need to perform the same task in different chains with different behavior. For chain A , I want to limit the number of restarts, so I specify this parameter when declaring the task itself

@shared_task(bind=True, max_retries=1)
task(args):
   pass

How can I override the max_retries parameter when calling a task from chain B so that the task restarts indefinitely?
chain(task.s(args).set(max_retries=None), task2...)
something does not work =(
Why do I think it should work?
The set method allows you to set options for the task called through the signature
You can't define options with s(), but a chaining set call takes care of that ( link )

Task.max_retries
The maximum number of attempted retries before giving up. If the number of retries exceeds this value a MaxRetriesExceededError exception will be raised.
The default is 3. A value of None will disable the retry limit and the task will retry forever until it succeeds.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Tikhonov, 2019-04-22
@tumbler

Signature initialization option without shortcuts:
The problem is that None somewhere inside means "not set" and defaults to the default 3 repetitions. In any case, this was the case in the days of 3.1. We modify task.request.retries inside for infinite repetitions.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question