0
0
Flaskframework~20 mins

Defining Celery tasks in Flask - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Celery Task Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the output of this Celery task call?

Given this Celery task defined in a Flask app, what will result.get() return?

Flask
from celery import Celery

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

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

result = add.delay(4, 5)
AReturns AsyncResult object
B9
CRaises AttributeError
DNone
Attempts:
2 left
💡 Hint

Remember that delay() queues the task and get() waits for the result.

📝 Syntax
intermediate
2:00remaining
Which option correctly defines a Celery task in Flask?

Choose the correct way to define a Celery task function in a Flask app.

A
@app.task
def multiply(x, y):
    return x * y
B
def multiply(x, y):
    return x * y
@app.task
C
@app.task()
def multiply(x, y):
    return x * y
D
@app.task
def multiply(x, y):
    print(x * y)
Attempts:
2 left
💡 Hint

Decorator syntax must be directly above the function definition without parentheses if no arguments.

state_output
advanced
2:00remaining
What is the value of result.status immediately after calling add.delay(2, 3)?

Consider this Celery task call:

result = add.delay(2, 3)

What is the value of result.status right after this line?

Flask
from celery import Celery

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

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

result = add.delay(2, 3)
A"STARTED"
B"SUCCESS"
C"FAILURE"
D"PENDING"
Attempts:
2 left
💡 Hint

Think about the task lifecycle immediately after queuing.

🔧 Debug
advanced
2:00remaining
Why does this Celery task raise an error?

Given this task definition, why does calling multiply.delay(3, 4) raise an error?

Flask
from celery import Celery

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

def multiply(x, y):
    return x * y

app.task(multiply)
AThe task decorator is not applied correctly; it should be @app.task above the function
BThe broker URL is invalid causing connection failure
CThe function multiply is missing a return statement
DThe task name is missing causing registration failure
Attempts:
2 left
💡 Hint

Check how the task decorator is used in Celery.

🧠 Conceptual
expert
3:00remaining
Which option best explains how Celery tasks are discovered in a Flask app?

In a Flask app using Celery, how does Celery find and register tasks defined in different modules?

ATasks must be explicitly imported in the Celery app module to be registered
BCelery uses a configuration setting to list all task names manually
CCelery auto-discovers tasks by scanning all Python files in the project directory
DTasks are registered only if decorated with @app.task and placed in the main app file
Attempts:
2 left
💡 Hint

Think about Python import behavior and how decorators work.