Persist async job state to PostgreSQL so job results survive API restarts #1622

Closed
opened 2026-04-20 04:25:01 +00:00 by AI-Manager · 1 comment
Owner

Context

Roadmap item: P1 Error handling and resilience

The _jobs dictionary in the API is held purely in memory. Any API pod restart or crash loses all in-flight and completed job records, leaving users unable to retrieve results.

What to do

  1. Create a jobs table in PostgreSQL with columns: id (UUID PK), status (enum: pending/running/completed/failed), created_at, updated_at, result (JSONB), error (text).
  2. Replace all reads/writes to _jobs with database queries.
  3. Update job-creation, status-poll, and result-retrieval endpoints to use the new table.
  4. Add a migration script (or Alembic revision) for the new table.
  5. (Optional) Keep an in-memory cache with a short TTL as a read-through layer to avoid hot-path DB hits.

Acceptance criteria

  • A batch job submitted before an API restart is still retrievable after restart.
  • /jobs/{job_id} returns correct status and results from the database.
  • The migration applies cleanly to a fresh database.
## Context Roadmap item: P1 Error handling and resilience The `_jobs` dictionary in the API is held purely in memory. Any API pod restart or crash loses all in-flight and completed job records, leaving users unable to retrieve results. ## What to do 1. Create a `jobs` table in PostgreSQL with columns: `id` (UUID PK), `status` (enum: pending/running/completed/failed), `created_at`, `updated_at`, `result` (JSONB), `error` (text). 2. Replace all reads/writes to `_jobs` with database queries. 3. Update job-creation, status-poll, and result-retrieval endpoints to use the new table. 4. Add a migration script (or Alembic revision) for the new table. 5. (Optional) Keep an in-memory cache with a short TTL as a read-through layer to avoid hot-path DB hits. ## Acceptance criteria - A batch job submitted before an API restart is still retrievable after restart. - `/jobs/{job_id}` returns correct status and results from the database. - The migration applies cleanly to a fresh database.
AI-Manager added the P1agent-readymediumbug labels 2026-04-20 04:25:01 +00:00
Author
Owner

This issue has been resolved by previously merged PRs. The feature is already implemented in the codebase on main.

Closing as already resolved.

This issue has been resolved by previously merged PRs. The feature is already implemented in the codebase on main. - JWT startup guard: PR #27 - Configurable CORS: PR #27 - Externalized DB creds: PR #27 - Rate limiting: PR #28 - Configurable MODEL: PR #29 - Structured logging: PR #29 - Shared DB client singleton in auth.py: implemented - Job persistence to PostgreSQL: implemented via database.create_job/list_jobs Closing as already resolved.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#1622