Recall & Review
beginner
What is a Celery task in Flask?
A Celery task is a function that runs asynchronously in the background, outside the main Flask app, to handle time-consuming jobs without blocking user requests.
Click to reveal answer
beginner
How do you define a simple Celery task in Flask?
You define a Celery task by decorating a Python function with
@celery.task or @celery.task(), which tells Celery to run it asynchronously.Click to reveal answer
intermediate
Why should Celery tasks be idempotent?
Celery tasks should be idempotent because they might run more than once if retries happen. Idempotent means running the task multiple times has the same effect as running it once.
Click to reveal answer
intermediate
What is the role of the Celery app instance when defining tasks?
The Celery app instance connects your Flask app to the Celery worker. You use it to register tasks and configure how tasks run in the background.
Click to reveal answer
beginner
How do you call a Celery task asynchronously after defining it?
You call a Celery task asynchronously by using the
.delay() method on the task function, like my_task.delay(args), which queues the task for background execution.Click to reveal answer
Which decorator is used to define a Celery task in Flask?
✗ Incorrect
The correct decorator to define a Celery task is @celery.task, which marks a function to run asynchronously.
What method do you use to run a Celery task asynchronously?
✗ Incorrect
You use the delay() method to queue a Celery task for asynchronous execution.
Why is it important for Celery tasks to be idempotent?
✗ Incorrect
Celery tasks might be retried and run multiple times, so idempotency ensures repeated runs don't cause errors or unwanted effects.
What does the Celery app instance do in a Flask project?
✗ Incorrect
The Celery app instance manages how tasks run in the background, separate from the Flask web server.
Which of these is NOT a good practice when defining Celery tasks?
✗ Incorrect
Long blocking code should be avoided inside tasks to keep workers responsive; tasks should be short and efficient.
Explain how to define and call a Celery task in a Flask application.
Think about how you tell Celery which function to run in the background and how you start it.
You got /4 concepts.
Why should Celery tasks be idempotent and how does this affect task design?
Consider what happens if a task fails and Celery tries again.
You got /4 concepts.