'Celerybeat Multiple schedules of the same task
I got following Celery beat task which cleans 1000 items daily at 1 AM:
from celery.schedules import crontab
from .celery import app as celery_app
celery_app.conf.beat_schedule['maintenance'] = {
'task': 'my_app.tasks.maintenance',
'schedule': crontab(hour=1, minute=0),
'args': (1000,)
}
I want to clean additional 5000 items every Sunday at 5PM. Is there a way to add second schedule?
'schedule': crontab(hour=17, minute=0, day_of_week='sunday'),
'args': (5000,)
And how to ensure they won't overlap?
Solution 1:[1]
Task1 will run every day including sunday and Task 2 will run only on sunday
app.conf.beat_schedule = {
'task1':{
'task':'my_app.tasks.maintenance',
'schedule': crontab(hour=1, minute=0),
'args': (1000,)
},
'task2':{
'task':'my_app.tasks.maintenance',
'schedule': crontab(minute=00, hour=17, day_of_week='sunday'),
'args': (5000,)
},
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Akram |
