Challenge - 5 Problems
Async Task Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output of this Django Celery task call?
Consider this Django Celery task defined in
tasks.py. What will be printed when the task is called asynchronously?Django
from celery import shared_task @shared_task def add(x, y): return x + y result = add.delay(4, 5) print(result.ready())
Attempts:
2 left
💡 Hint
Think about what
delay() returns and when the task finishes.✗ Incorrect
The delay() method queues the task and returns an AsyncResult immediately. The task is not finished yet, so result.ready() returns False.
❓ state_output
intermediate2:00remaining
What is the value of
result.get() after task completion?Given this Celery task and its asynchronous call, what will
result.get() return after the task finishes?Django
from celery import shared_task @shared_task def multiply(x, y): return x * y result = multiply.delay(3, 7) output = result.get(timeout=10) print(output)
Attempts:
2 left
💡 Hint
The
get() method waits for the task result.✗ Incorrect
The get() method blocks until the task completes or the timeout expires. Since the task multiplies 3 and 7, the result is 21.
📝 Syntax
advanced2:30remaining
Which option correctly schedules a periodic task in Django Celery?
You want to schedule a task to run every 10 minutes using Django Celery. Which code snippet correctly sets this up in
celery.py or tasks.py?Attempts:
2 left
💡 Hint
Look for the correct way to specify a periodic schedule using crontab.
✗ Incorrect
Option A uses crontab(minute='*/10') which correctly schedules the task every 10 minutes. Other options either use wrong keys or invalid schedule types.
🔧 Debug
advanced2:00remaining
Why does this asynchronous task call raise an error?
Examine the code below. Why does calling
send_email.delay() raise an error?Django
from celery import shared_task @shared_task def send_email(to_address): print(f"Sending email to {to_address}") send_email.delay()
Attempts:
2 left
💡 Hint
Check the function parameters and how delay() is called.
✗ Incorrect
The send_email task requires one argument to_address. Calling delay() without arguments causes a TypeError.
🧠 Conceptual
expert2:30remaining
Which statement about Django Celery task execution is true?
Select the correct statement about how Django Celery executes asynchronous tasks.
Attempts:
2 left
💡 Hint
Think about how Celery separates task execution from the Django app.
✗ Incorrect
Celery sends tasks to a message broker like RabbitMQ or Redis. Worker processes listen to the broker and execute tasks asynchronously, separate from the Django main process.