Increase celery retries every repeat cycle

I am repeating with celery, as in the example with Docs:

@task() def add(x, y): try: ... except Exception, exc: add.retry(exc=exc, countdown=60) # override the default and # retry in 1 minute 

How can I increase the countdown of retries every time a retry occurs for this job - for example. 60 seconds, 2 minutes, 4 minutes and so on until MaxRetriesExceeded is raised?

+14
python celery celeryd
Feb 27 '12 at 18:20
source share
2 answers

Here's an easy way to create a large delay with each task assessment. This value is updated by the celery itself, so you do not need to manage anything yourself.

 @task() def add(x, y): try: ... except Exception as exc: raise add.retry(exc=exc, countdown=60 * add.request.retries) 

Note. The first task is repeated with a countdown of 0. Since the number of repetitions for the first run is 0.

+27
Apr 11 '14 at 14:22
source share

Store the variable with your last retry time in it and multiply it by 2 each time until it exceeds any level you want (or, if you prefer a certain number of times),

+7
Feb 27 '12 at 18:23
source share



All Articles