Cron tools › Platforms
Celery crontab() converter
Convert a Linux cron line into crontab(minute=…, hour=…, …) for celery beat, or paste an existing
crontab() call to see the cron line it stands for and when it runs. Positional arguments, the classic source of wrong
schedules, are called out.
Python
Next runs
How to convert a cron line to Celery crontab()
- Paste the cron line (
minute hour day-of-month month day-of-week) under cron line → crontab(). - Copy the
crontab(…)call. It always uses keyword arguments, so the order cannot bite. - If the line sets both a day of the month and a weekday, you get two calls: Linux cron runs when either matches, Celery only when both do.
- Set the task name and entry name, then copy the
beat_scheduleblock into your Celery configuration. - To read an existing schedule, switch to crontab() → cron line and paste the call; strings, whole numbers and lists of numbers are understood.
- Pick the time zone your Celery app uses (UTC unless configured) to see the right run times.
The argument-order trap
A cron line lists the day fields as day-of-month, month, day-of-week. crontab() takes its arguments in a different order,
with day_of_week third:
| Position | Cron line field | crontab() argument |
|---|---|---|
| 1 | minute | minute |
| 2 | hour | hour |
| 3 | day of month | day_of_week |
| 4 | month | day_of_month |
| 5 | day of week | month_of_year |
So crontab('0', '0', '1') is not "midnight on the 1st": it is midnight every Monday. Keyword arguments remove the
problem. crontab.from_string('0 0 1 * *'), on the other hand, reads the cron-line order.
Where Celery differs from Linux cron
- Day of week is 0-6 with Sunday = 0; names like
mon-friwork, and 7 raises an error. - Day of month and day of week are ANDed, so a Linux OR needs two beat entries.
- Ranges that wrap work:
day_of_week='fri-mon'is Friday through Monday. day_of_week='*/2'means the days divisible by two (Sunday, Tuesday, Thursday, Saturday).- Schedules are evaluated in UTC unless you configure another time zone.
Other languages and schedulers for the same line are on cron to code.
FAQ
Why does my Celery task run on Mondays instead of the 1st?
You probably wrote crontab(0, 0, 1). The third positional argument is day_of_week, and 1 is Monday. Write
crontab(minute=0, hour=0, day_of_month=1).
How do I say "the 1st of the month or every Monday" in Celery?
With two beat entries, one with day_of_month='1' and one with day_of_week='1'. In one crontab()
both would have to match. Paste 0 0 1 * 1 above to get both entries.
Is Sunday 0 or 7 in Celery?
0 (or sun). Celery raises on 7, unlike Linux cron, where 7 is also Sunday.
Which time zone does celery beat use?
UTC by default. If your app sets app.conf.timezone, pick the same zone here to see the real run times; the generated
beat_schedule includes that setting when the zone is not UTC.