Bird
0
0

How can you ensure Flask app context is available inside a Celery task?

hard📝 Application Q9 of 15
Flask - Background Tasks
How can you ensure Flask app context is available inside a Celery task?
ASet broker URL to Flask app URL
BCall Flask app.run() inside the task
CPass Flask app instance as a task argument
DUse a custom task base class that pushes Flask app context
Step-by-Step Solution
Solution:
  1. Step 1: Understand Flask context in Celery tasks

    Celery tasks run outside Flask, so app context must be manually pushed.
  2. Step 2: Identify correct method

    Creating a custom task base class that pushes Flask app context ensures context availability.
  3. Final Answer:

    Use a custom task base class that pushes Flask app context -> Option D
  4. Quick Check:

    Custom task class manages Flask context in Celery [OK]
Quick Trick: Push Flask context in custom Celery task class [OK]
Common Mistakes:
MISTAKES
  • Trying to run Flask server inside task
  • Passing app instance as argument (not context)
  • Confusing broker URL with app URL

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes