If I create a celery beat schedule, using timedelta(days=1)
, the first task will be carried out after 24 hours, quote celery beat documentation:
Using a timedelta for the schedule means the task will be sent in 30 second intervals (the first task will be sent 30 seconds after celery beat starts, and then every 30 seconds after the last run).
But the fact is that in a lot of situations it's actually important that the the scheduler run the task at launch, But I didn't find an option that allows me to run the task immediately after celery starts, am I not reading carefully, or is celery missing this feature?
I decide I could just declare a instance of every task, and execute them at celery launch. I don't like this at all because it makes starting celery beat extremely slow (if you have slow
PeriodicTask
), but it does what I want.simply add this to the end of
tasks.py
:The best idea is create an implementation which schedules the task itself after completing the task. Also, create an entrance lock so the task cannot be executed multiple times per moment. Trigger the execution once.
In this case,