Bird
0
0

You want to run a background task that sends emails and also logs the result to a database. How can you design this using Flask and RQ?

hard📝 Conceptual Q8 of 15
Flask - Background Tasks
You want to run a background task that sends emails and also logs the result to a database. How can you design this using Flask and RQ?
ACreate two separate tasks: one for sending email, one for logging; enqueue both sequentially
BWrite one task that sends email and logs synchronously in the main Flask thread
CUse Flask signals instead of RQ for background processing
DRun the email sending code directly in the Flask route handler
Step-by-Step Solution
Solution:
  1. Step 1: Separate concerns into tasks

    Splitting email sending and logging into two tasks keeps code clean and asynchronous.
  2. Step 2: Enqueue tasks sequentially

    Enqueueing both tasks ensures they run in background without blocking Flask requests.
  3. Final Answer:

    Create two separate tasks: one for sending email, one for logging; enqueue both sequentially -> Option A
  4. Quick Check:

    Separate tasks for async steps = D [OK]
Quick Trick: Split complex jobs into multiple queued tasks [OK]
Common Mistakes:
MISTAKES
  • Doing all work synchronously in Flask
  • Using signals instead of task queue
  • Running long tasks in route handlers

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes