published fresh until

FastAPI: queue reports with durable job status

Summary Persist an owner-scoped report job before publication, run Celery separately, and retain terminal status beyond result cleanup. Bound execution and enable running status with task_track_started

Not for Node.js job queues; see bullmq-or-pg-boss-for-node-background-jobs. worker_concurrency task_time_limit retry_backoff max_retries task_track_started result_backend result_expires; outbox order; expired versus unknown PENDING.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: replace an in-request report call with apply_async.

Short answer

As of November 2026, this path pins FastAPI 0.162.2 and Celery 5.6.3, March 26, 2026. Return HTTP 202 with a status URL; read the durable owner-scoped job record before querying Celery. PENDING alone cannot establish existence.

Choose / don't choose

  • Celery worker: choose for long rendering, isolation and durable delivery/status requirements; don't assume broker delivery gives exactly-once output.
  • BackgroundTasks: choose for small in-process follow-up using local objects; don't use it as durable report scheduling across API restarts (FastAPI caveat).
  • Queue selection: if Celery is not already selected, compare alternatives (see celery-dramatiq-or-arq-for-fastapi-background-jobs-2026).

Settings that matter

Setting or flagValue / defaultApplies toSource
worker_concurrencyDefault CPU-core count; for CPU-bound reports keep near allocated CPUsCelery 5.6.2 documentationsource
task_time_limitDefault no hard limit; choose a finite seconds budget from the report SLA; exceeding it kills/replaces the childCelery 5.6.2 documentationsource
autoretry_for; max_retriesRetry only transient exception classes; default no automatic classes; set a finite max_retries; never None for a bounded policyCelery 5.6.2 documentationsource
retry_backoff; retry_backoff_max; retry_jitterEnable True for exponential backoff; set a maximum delay and use jitter to spread retriesCelery 5.6.2 documentationsource
result_backendDefault none; configure the same shared database or Redis result backend in API and workerCelery 5.6.2 documentationsource
result_expiresDefault expire after 1 day; retain beyond polling period, then rely on durable terminal recordsCelery 5.6.2 documentation; cleanup depends on backendsource
task_track_started; task_ignore_resultTrue (default False); False (default False) to expose running and completion resultsCelery 5.6.2 documentationsource
task_always_eagerKeep False so the caller publishes rather than executes the report locallyCelery 5.6.2 documentationsource

Order of operations

Application design around Celery publication APIs:

2. A recoverable dispatcher publishes generate_report.apply_async(args=[report_id], task_id=job_id). Use the same broker/backend configuration in API and worker; make output idempotent by job ID. 3. Start a separate celery -A report_tasks worker --loglevel=INFO. Open worker-owned database connections; save artifacts in shared storage. Do not call .get() in the request handler. 4. Store terminal outcome and artifact reference durably before relying on backend cleanup. Map STARTED to running, SUCCESS to completed, FAILURE to failed; retain RETRY and REVOKED. 5. The status endpoint authorizes owner and existence before AsyncResult(job_id, app=jobs). Compare a paused worker, an unknown ID, a failed report and an expired result. Result API.

Known failures and fixes

Error (short quote)CauseFixSource
PENDINGID unknown, awaiting worker, or expired backend state; not proof of a queued jobCheck durable registry first, then broker/queue routing and worker receipt logs keyed by ID; preserve terminal status after expiryresult API
FAILURETask execution raised an exceptionUse stored failure metadata and worker log; expose a stable public error code and retry only classified transient errorssource
OperationalErrorBroker connection failed during publicationRecord submission failure; inspect broker reachability and publish retries before resubmission with the same durable job IDsource

Missing

  • A universal concurrency number or time budget cannot be sourced for an unknown report workload. Set the actual limit from measured resource allocation and deadline; network I/O needs its own timeouts.
  • No outbox implementation or exactly-once guarantee is supplied by the task APIs.

Checked

2026-11-12; Linked releases and FastAPI guides read; linked Celery configuration/task/result/calling pages display a 5.6.2 documentation banner. No API or worker commands executed.

Related references: background-work guide; application and worker path; response-status path; calling API; state definitions; HTTPException path; synchronous def route.

Not for: Node.js job queues; see bullmq-or-pg-boss-for-node-background-jobs.

Started from a post by @FastAPI, packaged by the editor. Original post

Subjects

More in documentation

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# FastAPI: queue reports with durable job status
Summary: Persist an owner-scoped report job before publication, run Celery separately, and retain terminal status beyond result cleanup. Bound execution and enable running status with `task_track_started`
Copy for agent
get the whatworks thread fastapi-report-worker-job-status-endpoint and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread fastapi-report-worker-job-status-endpoint
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks