YPCrumble
YPCrumble

Reputation: 28722

What does max_retries and retry_backoff_max mean if retry_backoff is set to True in Celery?

The celery documentation gives the following example for automatically retrying a task:

class BaseTaskWithRetry(Task):
    autoretry_for = (TypeError,)
    retry_kwargs = {'max_retries': 5}
    retry_backoff = True
    retry_backoff_max = 700
    retry_jitter = False

retry_backoff means that Celery will use exponential backoff - so in this case (according to the docs):

The first retry will have a delay of 1 second, the second retry will have a delay of 2 seconds, the third will delay 4 seconds, the fourth will delay 8 seconds, and so on.

However, in the example max_retries is five, and yet retry_backoff_max is 700.

I would think that if max_retries is set to five, then the retries would happen at one second, two seconds, four seconds, eight seconds, and sixteen seconds. That is all, because that's five retries. The backoff never gets anywhere close to 700 seconds.

Is retry_backoff_max in the given example pointless? What does max_retries of five actually mean in this example?

Upvotes: 2

Views: 1660

Answers (1)

Tomáš Linhart
Tomáš Linhart

Reputation: 10220

I would say that in this specific example, setting retry_backoff_max is really superfluous. However, in general case, the task can initiate retry also using self.retry alongside using autoretry. If you look at how the countdown for task retry is calculated you'll see that it uses the actual retries count from the task (task.request.retries) instead of max_retries attribute. retry_backoff_max then represents the hard limit which accounts for both types of retry.

Upvotes: 1

Related Questions