0
0
Djangoframework~10 mins

Periodic tasks with Celery Beat in Django - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the Celery app instance in your Django project.

Django
from [1] import app as celery_app
Drag options to blanks, or click blank then click option'
Adjango_celery_beat
Bcelery
Cmyproject.celery
Dtasks
Attempts:
3 left
💡 Hint
Common Mistakes
Importing directly from 'celery' instead of your project celery file.
Using 'django_celery_beat' which is for scheduling, not the app instance.
2fill in blank
medium

Complete the code to define a periodic task using Celery Beat's @periodic_task decorator.

Django
@periodic_task(run_every=crontab(minute='*/[1]'))
def my_task():
    print('Task runs every 5 minutes')
Drag options to blanks, or click blank then click option'
A5
B0
C10
D15
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 which means only at the start of the hour.
Confusing the minute value with seconds.
3fill in blank
hard

Fix the error in the Celery Beat schedule dictionary to run a task every hour.

Django
CELERY_BEAT_SCHEDULE = {
    'hourly-task': {
        'task': 'app.tasks.my_task',
        'schedule': [1](hour='*', minute=0),
    },
}
Drag options to blanks, or click blank then click option'
Acrontab
Btimedelta
Cschedule
Dinterval
Attempts:
3 left
💡 Hint
Common Mistakes
Using timedelta which is not imported or used here.
Using interval which requires seconds, not crontab syntax.
4fill in blank
hard

Fill both blanks to create a periodic task that runs every day at midnight.

Django
CELERY_BEAT_SCHEDULE = {
    'daily-task': {
        'task': '[1]',
        'schedule': crontab(hour=[2], minute=0),
    },
}
Drag options to blanks, or click blank then click option'
Aapp.tasks.daily_cleanup
Bapp.tasks.hourly_cleanup
C0
D12
Attempts:
3 left
💡 Hint
Common Mistakes
Using hour 12 which is noon, not midnight.
Using the wrong task name.
5fill in blank
hard

Fill all three blanks to define a periodic task that runs every Monday at 7:30 AM.

Django
CELERY_BEAT_SCHEDULE = {
    'weekly-task': {
        'task': '[1]',
        'schedule': crontab(hour=[2], minute=[3], day_of_week='1'),
    },
}
Drag options to blanks, or click blank then click option'
Aapp.tasks.weekly_report
B7
C30
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using hour 0 which is midnight.
Confusing day_of_week numbers.