Challenge - 5 Problems
Celery Task Master
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 when called synchronously?
Consider this Django Celery task definition and its synchronous call. What will be printed?
Django
from celery import shared_task @shared_task def add(x, y): return x + y result = add(4, 5) print(result)
Attempts:
2 left
💡 Hint
Calling the task function directly runs it like a normal function.
✗ Incorrect
When you call a Celery task function directly (not using .delay() or .apply_async()), it runs immediately and returns the result. So print(result) outputs 9.
❓ state_output
intermediate2:00remaining
What is the type of result when calling a Celery task asynchronously?
Given this task call, what is the type of the variable 'result'?
Django
from celery import shared_task @shared_task def multiply(x, y): return x * y result = multiply.delay(3, 7) print(type(result))
Attempts:
2 left
💡 Hint
Using .delay() returns a special object representing the task execution.
✗ Incorrect
Calling .delay() on a Celery task returns an AsyncResult object that tracks the task status and result asynchronously.
📝 Syntax
advanced2:30remaining
Which option correctly defines a periodic task in Django Celery?
Select the correct way to define a periodic task that runs every 10 minutes using Celery beat.
Attempts:
2 left
💡 Hint
The schedule value must be a timedelta object, not an integer.
✗ Incorrect
The correct way is to define the task normally and configure the beat_schedule with a timedelta for the schedule. Option A uses timedelta(minutes=10) correctly.
🔧 Debug
advanced2:30remaining
Why does this Celery task raise an ImportError when called?
Given this task code, why does calling task.delay() raise ImportError: No module named 'myapp.tasks'?
Django
from celery import shared_task @shared_task def send_email(): from myapp.utils import send send() # Called from another module send_email.delay()
Attempts:
2 left
💡 Hint
Check if the module 'myapp.tasks' is discoverable by Celery worker.
✗ Incorrect
Celery workers must be able to import the task module. If 'myapp.tasks' is not in the Python path or not listed in INSTALLED_APPS, ImportError occurs.
🧠 Conceptual
expert3:00remaining
What happens if a Celery task raises an exception during execution?
When a Celery task raises an exception, which of the following is true about the task state and result?
Attempts:
2 left
💡 Hint
Celery tracks task failures explicitly.
✗ Incorrect
When a task raises an exception, Celery marks it as 'FAILURE' and stores the exception details for inspection.