Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import Celery in a Flask app.
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'.
Trying to import 'Flask' from celery.
✗ Incorrect
You import Celery from the celery package to create tasks.
2fill in blank
mediumComplete the code to create a Celery instance with Flask app's config.
Flask
celery = Celery(__name__, broker=[1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string literal instead of app config.
Using a wrong config key.
✗ Incorrect
The broker URL is usually stored in Flask app config under CELERY_BROKER_URL.
3fill in blank
hardFix the error in defining a Celery task decorator.
Flask
@celery.[1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using @celery.tasks which does not exist.
Using @celery.run or @celery.execute which are invalid.
✗ Incorrect
The correct decorator to define a Celery task is @celery.task.
4fill in blank
hardFill both blanks to define a simple Celery task function.
Flask
@celery.[1] def [2](): return 'Hello from Celery!'
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using invalid decorator names.
Using function names with spaces or invalid characters.
✗ Incorrect
The decorator is @celery.task and the function name can be hello_task.
5fill in blank
hardFill all three blanks to create a Celery task that adds two numbers.
Flask
@celery.[1] def [2](a, b): return a [3] b
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction instead of addition.
Using wrong decorator or function names.
✗ Incorrect
The decorator is @celery.task, the function name add_numbers, and the operator is + to add.