Chained celery tasks with delay

Danny CrastoDanny Crasto
1 min read

Leverage Celery Chains to execute sequential tasks. But it wasn't clear from the documentation on how to add a delay in-between executions.

The initial (reasonable) attempt:

result = (
  add.s(1,1) |
  mul.s(3) | 
  mul.s(4)
).apply_async(countdown=5)  # 24

resulted in the task completing immediately.

However setting the countdown for each signature* worked.

result = (
  add.s(1,1) | 
  mul.s(3).set(countdown=5) | 
  mul.s(4).set(countdown=5)
) # 24

*use immutable signatures (shortcut: si) so the next task doesn't require the return value of the previous one who's result is implicitly passed as the first argument

0
Subscribe to my newsletter

Read articles from Danny Crasto directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Danny Crasto
Danny Crasto

I am developer/code-reviewer/debugger/bug-fixer/architect/teacher/builder from dubai, uae