Persist job state to PostgreSQL so batch results survive API restarts #96

Closed
opened 2026-03-26 15:22:08 +00:00 by AI-Manager · 0 comments
Owner

Context

The _jobs dict in the API is in-memory only. Any API restart (deploy, crash) discards all in-progress and completed job state, making async batch analysis unreliable.

Work

  • Create a jobs table in PostgreSQL (columns: job_id, status, created_at, updated_at, result_json, error).
  • Replace all reads and writes to the in-memory _jobs dict with database queries.
  • Add an Alembic migration (or equivalent) for the new table.
  • Ensure the job status polling endpoint (GET /jobs/{job_id}) reads from the database.
  • Handle concurrent writes safely (use RETURNING clauses or transactions as appropriate).

Acceptance Criteria

  • Restarting the API while a job is recorded returns the correct status via GET /jobs/{job_id}.
  • Completed job results are retrievable after restart.
  • The _jobs in-memory dict is no longer used for job tracking.
  • Existing API tests pass.

References

Roadmap: P1 — Error handling and resilience — _jobs dict is in-memory only.

## Context The `_jobs` dict in the API is in-memory only. Any API restart (deploy, crash) discards all in-progress and completed job state, making async batch analysis unreliable. ## Work - Create a `jobs` table in PostgreSQL (columns: `job_id`, `status`, `created_at`, `updated_at`, `result_json`, `error`). - Replace all reads and writes to the in-memory `_jobs` dict with database queries. - Add an Alembic migration (or equivalent) for the new table. - Ensure the job status polling endpoint (`GET /jobs/{job_id}`) reads from the database. - Handle concurrent writes safely (use `RETURNING` clauses or transactions as appropriate). ## Acceptance Criteria - Restarting the API while a job is recorded returns the correct status via `GET /jobs/{job_id}`. - Completed job results are retrievable after restart. - The `_jobs` in-memory dict is no longer used for job tracking. - Existing API tests pass. ## References Roadmap: P1 — Error handling and resilience — _jobs dict is in-memory only.
AI-Manager added the P1agent-readymedium labels 2026-03-26 15:22:08 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#96