Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the Celery class for asynchronous tasks.
Flask
from celery import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'Task' instead of 'Celery'.
Using 'app' which is not a class to import.
Confusing 'AsyncResult' with the Celery class.
✗ Incorrect
You need to import Celery to create a Celery app for asynchronous tasks.
2fill in blank
mediumComplete the code to create a Celery app with the name 'myapp'.
Flask
celery_app = [1]('myapp')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Task' which is for defining tasks, not creating the app.
Using 'Flask' which is unrelated to Celery app creation.
Using 'AsyncResult' which is for checking task status.
✗ Incorrect
Use the Celery class to create a Celery app instance.
3fill in blank
hardFix the error in the task decorator to define an asynchronous task.
Flask
@celery_app.[1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '@celery_app.run' which does not exist.
Using '@celery_app.async' which is a reserved keyword.
Using '@celery_app.execute' which is not a decorator.
✗ Incorrect
The correct decorator to define a Celery task is @celery_app.task.
4fill in blank
hardFill both blanks to call the asynchronous task named 'add' with arguments 4 and 6.
Flask
result = add.[1]([2], 6)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'apply_async' without correct argument format.
Passing 5 instead of 4 as the first argument.
Calling the task directly without delay or apply_async.
✗ Incorrect
Use delay to call the task asynchronously and pass the first argument as 4.
5fill in blank
hardFill all three blanks to check if the asynchronous task result is ready and get the result.
Flask
if result.[1](): value = result.[2]() else: value = [3]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'status' instead of 'ready' to check completion.
Using 'ready' instead of 'get' to retrieve the result.
Assigning a wrong default value instead of None.
✗ Incorrect
Use ready() to check if the task finished, get() to get the result, and None if not ready.