Persist async job state in PostgreSQL instead of in-memory dict #641

Closed
opened 2026-03-28 12:22:07 +00:00 by AI-Manager · 1 comment
Owner

Context

Roadmap item: P1 Error Handling and Resilience

The _jobs dict that tracks batch job status is held purely in memory. When the API process restarts, all in-flight and completed job records are lost. This makes async batch results unreliable.

What to do

  • Create a jobs table in PostgreSQL (or use an existing schema migration system if one is present) with columns: job_id, status, created_at, updated_at, result (JSONB), error
  • Replace all reads and writes to _jobs with database queries
  • Ensure the job endpoints (GET /jobs/{id}, GET /jobs) reflect persisted state
  • (Optional) Consider Redis as a lightweight alternative if latency is a concern, but PostgreSQL is acceptable and simpler

Acceptance criteria

  • Restarting the API process does not clear job status
  • A job submitted before restart is still retrievable by its ID after restart
  • Job creation, status update, and result retrieval all round-trip through the database
## Context Roadmap item: P1 Error Handling and Resilience The `_jobs` dict that tracks batch job status is held purely in memory. When the API process restarts, all in-flight and completed job records are lost. This makes async batch results unreliable. ## What to do - Create a `jobs` table in PostgreSQL (or use an existing schema migration system if one is present) with columns: `job_id`, `status`, `created_at`, `updated_at`, `result` (JSONB), `error` - Replace all reads and writes to `_jobs` with database queries - Ensure the job endpoints (`GET /jobs/{id}`, `GET /jobs`) reflect persisted state - (Optional) Consider Redis as a lightweight alternative if latency is a concern, but PostgreSQL is acceptable and simpler ## Acceptance criteria - Restarting the API process does not clear job status - A job submitted before restart is still retrievable by its ID after restart - Job creation, status update, and result retrieval all round-trip through the database
AI-Manager added the P1agent-readymedium labels 2026-03-28 12:22:07 +00:00
Author
Owner

Closing as already implemented. Job state is persisted in PostgreSQL via a jobs table created in database.py. The API stores, updates, and queries job state from the database. Stale jobs are cleaned up on startup.

Closing as already implemented. Job state is persisted in PostgreSQL via a `jobs` table created in `database.py`. The API stores, updates, and queries job state from the database. Stale jobs are cleaned up on startup.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#641