0
0
Djangoframework~10 mins

Calling tasks asynchronously 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 call the Celery task asynchronously.

Django
from tasks import send_email

send_email.[1]()
Drag options to blanks, or click blank then click option'
Acall
Brun
Cexecute
Ddelay
Attempts:
3 left
💡 Hint
Common Mistakes
Using run() instead of delay() causes the task to run synchronously.
Using call() or execute() are not valid Celery task methods.
2fill in blank
medium

Complete the code to import the Celery app instance correctly.

Django
from [1] import app as celery_app
Drag options to blanks, or click blank then click option'
Amyproject.celery
Bdjango_celery
Ccelery_app
Dtasks
Attempts:
3 left
💡 Hint
Common Mistakes
Importing from 'tasks' instead of the celery app module.
Using a non-existent module like 'django_celery'.
3fill in blank
hard

Fix the error in the code to schedule a task with arguments asynchronously.

Django
send_email.[1](user_id=42, subject='Hello')
Drag options to blanks, or click blank then click option'
Asend
Bapply_async
Crun
Dexecute
Attempts:
3 left
💡 Hint
Common Mistakes
Using run() runs the task immediately and synchronously.
Using send() or execute() are invalid Celery task methods.
4fill in blank
hard

Fill both blanks to create a periodic task using Celery beat.

Django
from celery.schedules import [1]

app.conf.beat_schedule = {
    'send-report-every-day': {
        'task': 'tasks.send_report',
        'schedule': [2](hours=24),
    },
}
Drag options to blanks, or click blank then click option'
Acrontab
Btimedelta
Cinterval
Dperiodic
Attempts:
3 left
💡 Hint
Common Mistakes
Using crontab without proper syntax.
Using periodic which is not a valid import.
5fill in blank
hard

Fill all three blanks to retry a failed task after 10 seconds.

Django
@app.task(bind=True, max_retries=3)
def send_notification(self, user_id):
    try:
        # send notification logic
        pass
    except Exception as exc:
        raise self.[1](exc, countdown=[2]) from exc

# Call the task
send_notification.[3](user_id=5)
Drag options to blanks, or click blank then click option'
Aretry
B10
Cdelay
Dapply_async
Attempts:
3 left
💡 Hint
Common Mistakes
Using apply_async instead of delay to call the task.
Not using retry method inside the except block.