Performance: Periodic tasks with Celery Beat
This affects backend task scheduling and indirectly impacts frontend responsiveness and server load during task execution.
Jump into concepts and practice - no test required
from celery import shared_task from celery.schedules import crontab from celery import Celery app = Celery('proj') @app.on_after_configure.connect def setup_periodic_tasks(sender, **kwargs): sender.add_periodic_task( crontab(minute='*/5'), heavy_task.s(), name='run every 5 minutes' ) @shared_task def heavy_task(): # heavy processing pass
from celery import shared_task @shared_task def heavy_task(): # heavy processing pass # Using a custom infinite loop or cron job outside Celery Beat to trigger tasks
| Pattern | Task Scheduling | Server Load | Task Overlap | Verdict |
|---|---|---|---|---|
| Custom loops or cron jobs | Manual, error-prone | High spikes | Possible overlaps | [X] Bad |
| Celery Beat scheduling | Automated, reliable | Balanced load | No overlaps | [OK] Good |
beat_schedule = {
'print-time': {
'task': 'app.tasks.print_time',
'schedule': crontab(minute='*/15')
}
}
What will happen when Celery Beat and worker run?beat_schedule = {
'cleanup-task': {
'task': 'app.tasks.cleanup',
'schedule': crontab(minute=0, hour='*')
}
}
But the task never runs. What is the most likely cause?beat_schedule to achieve this?