[Django]-How can I defer the execution of Celery tasks?

26πŸ‘

βœ…

eta/countdown options enable to delay the task execution:

https://docs.celeryq.dev/en/stable/userguide/calling.html#eta-and-countdown

πŸ‘€mher

2πŸ‘

I think you are trying to avoid race condition of your own scripts, not asking for a method to delay a task run.

Then you can create a task, and in that task, call each of your task with .apply(), not .apply_async() or .delay(). So that these tasks run sequentially

πŸ‘€Yefei

1πŸ‘

To define delay on task execution use apply_async() with countdown option in the following format:

from datetime import timedelta
#Delay for 10 seconds
T.apply_async(args=[arg1, arg2], countdown = 10)
#Delay for 10 days 
T.apply_async(args=[arg1, arg2], countdown = timedelta(days=10))

By using timedelta it is possible to define more complicated delays for task execution.
Note that delay() is another calling API but does not support countdown for delay.

Leave a comment