I have some tasks in Celery that are scheduled with Celery Beat/Crontab like this:
CELERYBEAT_SCHEDULE = {
'task-1': {
'task': 'tasks.run_task1',
'schedule': crontab(hour=5, minute=30, day_of_week='mon-fri'),
},
'task-2': {
'task': 'tasks.run_task2',
'schedule': crontab(hour=12, minute=0, day_of_week='sun-fri'),
},
}
Sometimes I have the Celery process turned off and when I turn it back on at 4:00pm, it will run the tasks from earlier in the day. How can I make it so that these tasks will only run within ~5 minutes of when they are actually scheduled and NOT start to run later in the day?
Use the expires option:
CELERYBEAT_SCHEDULE = {
'task-1': {
'task': 'tasks.run_task1',
'schedule': crontab(hour=5, minute=30, day_of_week='mon-fri'),
'options': {
'expires': 5*60,
},
},
'task-2': {
'task': 'tasks.run_task2',
'schedule': crontab(hour=12, minute=0, day_of_week='sun-fri'),
'options': {
'expires': 5*60,
},
},
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With