Reputation: 36463
I read the docs on Celery tasks and can't understand how I do what I need.
I want to start a task, run and retry it every 1 second. After 3 seconds it should stop retrying and return a default value.
Here's a POC code that doesn't work as expected:
@task(expires=3, default_retry_delay=1, max_retries=10)
def ttt(args):
try:
return slow_work_result(args)
except SlowWorkFailed:
pass
try:
return ttt.retry(countdown=1)
except MaxRetriesExceededError:
return False
ttt.apply_async(args=(1,)).get()
The task should expire in 3 seconds, but MaxRetriesExceededError
should be raised in 10 seconds. But when I run it, it stops because of MaxRetriesExceededError
.
What am I doing wrong?
Can this try-except construct be more elegant?
Upvotes: 1
Views: 1405
Reputation: 3394
I wrote a task decorate to retry task maybe that can solve your problem.
https://gist.github.com/3958777
Upvotes: 1