Design a Flask application to handle long-running tasks asynchronously.
Instruction: Propose an architecture for a Flask application that processes long-running tasks in the background without blocking the main application thread.
Context: This question assesses the candidate's expertise in designing Flask applications for asynchronous task processing, crucial for maintaining application responsiveness.
Updated
Official answer available
Read the opening below, then unlock the full answer and practical guidance.
Model the operation as a durable job with an owner, input reference, state and result/error metadata. The HTTP request validates and authorizes the request, records the job and returns202 with an authorized status URL when processing is asynchronous.
Use a separate worker pool and broker for execution. If the job record and broker publication must remain consistent, record an outbox event in the same database transaction and publish it through a retrying dispatcher...