0
0
Flaskframework~20 mins

Celery integration overview in Flask - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Celery Integration Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What happens when a Celery task is called with .delay() in Flask?

Consider a Flask app using Celery for background tasks. When you call a task with .delay(), what is the immediate behavior?

Flask
from celery import Celery

celery_app = Celery('tasks', broker='redis://localhost:6379/0')

@celery_app.task
def add(x, y):
    return x + y

result = add.delay(4, 6)
AThe task is sent to the Celery worker queue and returns an AsyncResult immediately without blocking.
BThe task raises an error because .delay() is not a valid method for Celery tasks.
CThe task runs in a new thread inside the Flask app and blocks until completion.
DThe task runs immediately in the current Flask process and returns the result synchronously.
Attempts:
2 left
💡 Hint

Think about how Celery handles tasks asynchronously.

📝 Syntax
intermediate
1:30remaining
Which Celery configuration option sets the message broker URL in Flask?

In a Flask app integrating Celery, you need to configure the broker URL. Which option correctly sets the broker URL?

Acelery_app.conf.broker_url = 'redis://localhost:6379/0'
Bcelery_app.config['BROKER'] = 'redis://localhost:6379/0'
Ccelery_app.broker = 'redis://localhost:6379/0'
Dcelery_app.set_broker('redis://localhost:6379/0')
Attempts:
2 left
💡 Hint

Look for the official Celery configuration attribute for the broker URL.

state_output
advanced
2:00remaining
What is the value of result.ready() immediately after calling a Celery task with .delay()?

Given the code below, what does result.ready() return immediately after add.delay(2, 3) is called?

Flask
from celery import Celery

celery_app = Celery('tasks', broker='redis://localhost:6379/0')

@celery_app.task
def add(x, y):
    return x + y

result = add.delay(2, 3)
ready_state = result.ready()
ANone, because the task result is not available until .get() is called.
BTrue, because the task completes instantly in the same process.
CRaises an AttributeError because .ready() is not a valid method.
DFalse, because the task is queued and not completed immediately.
Attempts:
2 left
💡 Hint

Think about asynchronous task execution and when results become ready.

🔧 Debug
advanced
2:30remaining
Why does this Flask app with Celery fail to execute tasks?

Examine the code below. Why will the Celery tasks never run?

Flask
from flask import Flask
from celery import Celery

app = Flask(__name__)
celery = Celery(app.name, broker='redis://localhost:6379/0')

@celery.task
def multiply(x, y):
    return x * y

@app.route('/start')
def start_task():
    multiply.delay(5, 6)
    return 'Task started'
AThe Flask app must call celery.start() to run tasks, which is missing.
BThe Celery worker process is not running, so tasks are never executed.
CThe broker URL is incorrect and causes connection failure.
DThe task function multiply is not decorated properly with @app.task.
Attempts:
2 left
💡 Hint

Think about what runs Celery tasks in the background.

🧠 Conceptual
expert
3:00remaining
How does Celery ensure task results are accessible after asynchronous execution in Flask?

In a Flask app using Celery, how are task results stored and retrieved after the task completes?

AResults are returned directly to the Flask route that called the task without any backend storage.
BTask results are stored in Flask's session object automatically after task completion.
CCelery stores results in a backend like Redis or a database configured as the result backend, accessible via AsyncResult.
DCelery writes results to local files on the worker machine, which Flask reads later.
Attempts:
2 left
💡 Hint

Consider how asynchronous systems keep track of results separately from the main app.