Bird
0
0

Identify the error in this Flask RQ task definition:

medium📝 Debug Q6 of 15
Flask - Background Tasks
Identify the error in this Flask RQ task definition:
from rq import Queue
from redis import Redis

redis_conn = Redis()
queue = Queue(connection=redis_conn)

def background_task(x):
    return x * 2

queue.enqueue(background_task)
AQueue must be created inside the task function
Benqueue is missing the argument for the task function
Cbackground_task should be decorated with @app.task
DRedis connection is not initialized
Step-by-Step Solution
Solution:
  1. Step 1: Check enqueue usage

    enqueue requires the function and its arguments; here no argument is passed.
  2. Step 2: Validate other parts

    Redis connection is initialized; no decorator needed; queue creation outside is fine.
  3. Final Answer:

    enqueue is missing the argument for the task function -> Option B
  4. Quick Check:

    enqueue needs function args = D [OK]
Quick Trick: Always pass task arguments when enqueueing [OK]
Common Mistakes:
MISTAKES
  • Forgetting to pass function arguments
  • Thinking @app.task decorator is required
  • Misplacing queue creation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes