Complete the code to import the Celery app instance in your Django project.
from [1] import app as celery_app
You import the Celery app instance from your project's celery.py file, usually at myproject.celery.
Complete the code to define a periodic task using Celery Beat's @periodic_task decorator.
@periodic_task(run_every=crontab(minute='*/[1]')) def my_task(): print('Task runs every 5 minutes')
The crontab(minute='*/5') means the task runs every 5 minutes.
Fix the error in the Celery Beat schedule dictionary to run a task every hour.
CELERY_BEAT_SCHEDULE = {
'hourly-task': {
'task': 'app.tasks.my_task',
'schedule': [1](hour='*', minute=0),
},
}timedelta which is not imported or used here.interval which requires seconds, not crontab syntax.The crontab function is used to schedule periodic tasks with specific time patterns like every hour.
Fill both blanks to create a periodic task that runs every day at midnight.
CELERY_BEAT_SCHEDULE = {
'daily-task': {
'task': '[1]',
'schedule': crontab(hour=[2], minute=0),
},
}The task name is app.tasks.daily_cleanup and crontab(hour=0, minute=0) runs it at midnight daily.
Fill all three blanks to define a periodic task that runs every Monday at 7:30 AM.
CELERY_BEAT_SCHEDULE = {
'weekly-task': {
'task': '[1]',
'schedule': crontab(hour=[2], minute=[3], day_of_week='1'),
},
}The task app.tasks.weekly_report runs at 7:30 AM (hour=7, minute=30) every Monday (day_of_week='1').