I am using Django with celery beat. I would like to configure the cron schedule via env var (string value of the cron).
We are currently setting the cron schedule like this, using celery.schedules.crontab:
CELERY_BEAT_SCHEDULE = {
"task_name": {
"task": "app.tasks.task_function",
"schedule": crontab(minute=0, hour='1,3,5,13,15,17,19,21,23'),
},
}
I would like to configure the schedule by passing a crontab in string format, like this:
CELERY_BEAT_SCHEDULE = {
"task_name": {
"task": "app.tasks.task_function",
"schedule": '0 15 10 ? * *',
},
}
However, I cannot find any documentation for how I can do this. The naive attempt above does not work. I could parse the cron string into minute/hour/day etc values, and then pass them into crontab with the relevant kwargs, but that feels quite messy. It seems there should be an elegant way to do this.