Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the task decorator from Celery.
Django
from celery import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'task' instead of 'shared_task' causes import errors.
Importing 'app' is incorrect for task decorators.
✗ Incorrect
The shared_task decorator is used to define tasks in Django with Celery without needing the app instance.
2fill in blank
mediumComplete the code to define a simple Celery task that adds two numbers.
Django
@shared_task def add(x, y): return x [1] y
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-' subtracts instead of adds.
Using '*' or '/' changes the operation to multiplication or division.
✗ Incorrect
The task adds two numbers, so the operator must be +.
3fill in blank
hardFix the error in the task definition by completing the decorator correctly.
Django
@[1]_task def multiply(x, y): return x * y
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '@task_task' causes syntax errors.
Using '@celery_task' is invalid.
✗ Incorrect
The correct decorator is @shared_task to define a reusable Celery task.
4fill in blank
hardFill both blanks to create a task that sends an email asynchronously.
Django
from celery import [1] @[2] def send_email(to, subject, body): # email sending logic here pass
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing 'task' and 'shared_task' causes import or decorator errors.
Using 'app' or 'worker' is incorrect here.
✗ Incorrect
Import shared_task and use @shared_task decorator to define the asynchronous task.
5fill in blank
hardFill all three blanks to define a periodic task that runs every minute.
Django
from celery import [1] from celery.schedules import [2] @[3]() def periodic_task(): print('Runs every minute')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'task' instead of 'shared_task' for decorator causes errors.
Using 'app' or 'worker' is incorrect for these imports.
✗ Incorrect
Use shared_task to import and decorate the task, and crontab to schedule periodic tasks.