Celery Beat Crontab Schedules
Schedule recurring Celery tasks with beat crontabs, mixing timezones, staggered offsets, and task-specific routing to dedicated queues.
Code
from celery import Celery
from celery.schedules import crontab
app = Celery('ops', broker='redis://localhost:6379/1')
app.conf.update(
timezone='UTC',
beat_schedule={
'nightly-invoice-close': {
'task': 'tasks.close_invoices',
'schedule': crontab(hour=2, minute=0),
'options': {'queue': 'billing'},
},
'cache-warm-every-15min': {
'task': 'tasks.warm_cache',
'schedule': crontab(minute='*/15'),
'options': {'queue': 'maintenance'},
},
'staggered-region-reports': {
'task': 'tasks.region_report',
'schedule': crontab(hour=6, minute=30, day_of_week='mon'),
'args': ('eu',),
'options': {'queue': 'reporting'},
},
'monthly-compliance-export': {
'task': 'tasks.compliance_export',
'schedule': crontab(day=1, hour=3, minute=0),
'options': {'queue': 'reporting', 'expires': 7200},
},
},
)
@app.task(queue='billing')
def close_invoices() -> dict:
return {'closed': 42}
@app.task(queue='maintenance')
def warm_cache() -> dict:
return {'warmed': ['rates', 'catalog']}
@app.task(queue='reporting')
def region_report(region: str) -> dict:
return {'region': region, 'rows': 128}
@app.task(queue='reporting')
def compliance_export() -> dict:
return {'archive': 'compliance-2026-10.zip'}Inside the snippet
Count the functions close_invoices, warm_cache, region_report and compliance_export as the entire surface area of Celery Beat Crontab Schedules.
From celery it pulls Celery, crontab — the imports name exactly which library surface the snippet touches.
Returns a newly built value, leaving the inputs as they were.
Points of care
celerymust be installed first — the snippet imports it directly.
Putting it to use
The main signature reads def close_invoices() -> dict
Treat close_invoices as the API: import it, and ignore the supporting code.
Core lines
return {'archive': 'compliance-2026-10.zip'}
return {'warmed': ['rates', 'catalog']}
return {'region': region, 'rows': 128}
Interactive Tools for This Topic
Cron Expression ExplainerParse a five-field cron expression and get a field-by-field plain-English explanation plus a one-line human-readable schedule summary.Crontab Schedule GeneratorBuild standard 5-field cron expressions visually with field presets or custom ranges and preview the next 10 UTC and local execution timestamps.HTTP Retry & Backoff CalculatorSimulate exponential backoff retry schedules with Full, Equal, Decorrelated, or No Jitter to inspect per-attempt wait times and cumulative latency.Cron Next Runs CalculatorCompute the next scheduled run times for a standard five-field cron expression, supporting ranges, lists, steps, and day-of-week naming semantics.
FAQ
- Does `close_invoices` modify its input?
- No. The code builds and returns a new value and leaves the arguments untouched, so it is safe to call on shared or frozen data structures.
- Are there third-party dependencies?
- `celery` — install it with the package manager before running.
Report a problem with this exampleOpens a pre-filled issue on GitHub.