Periodic task scheduling patterns with Celery Beat (crontab, interval, solar). Use when configuring periodic tasks, setting up task schedules, implementing recurring jobs, configuring django-celery-beat, or creating dynamic schedules.
Limited to specific tools
Additional assets for this skill
This skill is limited to using the following tools:
examples/crontab-examples.mdexamples/django-celery-beat-setup.mdexamples/interval-examples.mdscripts/test-beat.shscripts/validate-schedule.shtemplates/crontab-schedule.pytemplates/django-celery-beat.pytemplates/dynamic-schedules.pytemplates/interval-schedule.pytemplates/solar-schedule.pyProvides comprehensive patterns and templates for implementing periodic task scheduling with Celery Beat, including crontab, interval, and solar schedules.
Generate crontab-based schedules with precise timing control:
# See templates/crontab-schedule.py for complete implementation
from celery.schedules import crontab
app.conf.beat_schedule = {
'daily-report': {
'task': 'tasks.generate_report',
'schedule': crontab(hour=0, minute=0), # Midnight daily
},
'business-hours': {
'task': 'tasks.process_orders',
'schedule': crontab(hour='9-17', minute='*/15', day_of_week='mon-fri'),
}
}
Key patterns:
Simple interval-based recurring tasks:
# See templates/interval-schedule.py for complete implementation
from celery.schedules import schedule
app.conf.beat_schedule = {
'every-30-seconds': {
'task': 'tasks.check_status',
'schedule': 30.0, # Execute every 30 seconds
},
'every-hour': {
'task': 'tasks.cleanup',
'schedule': timedelta(hours=1),
}
}
Key patterns:
Event-based scheduling using solar calculations:
# See templates/solar-schedule.py for complete implementation
from celery.schedules import solar
app.conf.beat_schedule = {
'morning-task': {
'task': 'tasks.sunrise_routine',
'schedule': solar('sunrise', 40.7128, -74.0060), # NYC coordinates
}
}
Supported events: sunrise, sunset, dawn_civil, dusk_astronomical, solar_noon
Database-backed dynamic schedules:
# See templates/django-celery-beat.py for complete implementation
# Schedules stored in Django database, editable via Django Admin
INSTALLED_APPS += ['django_celery_beat']
CELERY_BEAT_SCHEDULER = 'django_celery_beat.schedulers:DatabaseScheduler'
Benefits:
Programmatic schedule registration:
# See templates/dynamic-schedules.py for complete implementation
from celery import Celery
app = Celery('tasks')
@app.on_after_configure.connect
def setup_periodic_tasks(sender, **kwargs):
# Add tasks programmatically
sender.add_periodic_task(30.0, check_status.s(), name='status-check')
sender.add_periodic_task(
crontab(hour=7, minute=30),
morning_report.s(),
name='morning-report'
)
File: templates/crontab-schedule.py
Use for precise timing requirements:
File: templates/interval-schedule.py
Use for fixed interval tasks:
File: templates/solar-schedule.py
Use for location-based timing:
File: templates/django-celery-beat.py
Use for runtime schedule management:
File: templates/dynamic-schedules.py
Use for programmatic configuration:
Validates schedule configuration syntax and structure.
Usage:
bash scripts/validate-schedule.sh <config-file>
Checks:
Tests Celery Beat configuration and execution.
Usage:
bash scripts/test-beat.sh <celery-app>
Tests:
Determine the appropriate scheduling pattern:
Load the appropriate template for your schedule type:
# For crontab schedules
Read: templates/crontab-schedule.py
# For interval schedules
Read: templates/interval-schedule.py
# For Django integration
Read: templates/django-celery-beat.py
Customize the template with your task details:
Run validation to catch errors:
bash scripts/validate-schedule.sh celeryconfig.py
Verify schedule works as expected:
bash scripts/test-beat.sh myapp
Start Celery Beat in production:
celery -A myapp beat --loglevel=info
'daily-report': {
'task': 'reports.generate_daily',
'schedule': crontab(hour=0, minute=0),
}
'business-hours-sync': {
'task': 'sync.external_api',
'schedule': crontab(hour='9-17', minute='*/15', day_of_week='mon-fri'),
}
'health-check': {
'task': 'monitoring.check_services',
'schedule': 30.0, # Every 30 seconds
}
'weekend-cleanup': {
'task': 'maintenance.cleanup',
'schedule': crontab(hour=2, minute=0, day_of_week='sat,sun'),
}
This skill follows strict security rules:
.gitignore protection documentedapp.conf.timezone = 'UTC'expires option to prevent old task executionSee examples/ directory for detailed implementation examples:
crontab-examples.md - Comprehensive crontab schedule patternsinterval-examples.md - Interval schedule use casesdjango-celery-beat-setup.md - Complete Django integration guide