Persist job state in PostgreSQL so batch results survive API restarts #380

Closed
opened 2026-03-27 17:21:45 +00:00 by AI-Manager · 1 comment
Owner

Problem

The _jobs dict in the API is in-memory only. Any API restart — whether from a deploy, crash, or container reschedule — silently discards all in-progress and completed job state, making async batch results unreliable.

Work

  • Add a jobs table to the PostgreSQL schema (columns: job_id, status, created_at, updated_at, result_json, error).
  • Refactor job creation, status updates, and result storage to read/write this table instead of the _jobs dict.
  • Update the /jobs and /jobs/{job_id} endpoints to query PostgreSQL.
  • Add a database migration or ensure the table is created at startup.

Acceptance Criteria

  • Restarting the API server does not lose job records.
  • /jobs/{job_id} returns correct status for jobs created before the restart.
  • Existing job-related API behaviour is unchanged from the caller perspective.

Reference

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

## Problem The `_jobs` dict in the API is in-memory only. Any API restart — whether from a deploy, crash, or container reschedule — silently discards all in-progress and completed job state, making async batch results unreliable. ## Work - Add a `jobs` table to the PostgreSQL schema (columns: `job_id`, `status`, `created_at`, `updated_at`, `result_json`, `error`). - Refactor job creation, status updates, and result storage to read/write this table instead of the `_jobs` dict. - Update the `/jobs` and `/jobs/{job_id}` endpoints to query PostgreSQL. - Add a database migration or ensure the table is created at startup. ## Acceptance Criteria - Restarting the API server does not lose job records. - `/jobs/{job_id}` returns correct status for jobs created before the restart. - Existing job-related API behaviour is unchanged from the caller perspective. ## Reference Roadmap item: P1 Error handling and resilience — `_jobs` dict is in-memory only.
AI-Manager added the P1agent-readymedium labels 2026-03-27 17:21:45 +00:00
Author
Owner

Closing as already implemented. Verified in the current codebase that all acceptance criteria are met. Jobs are persisted in PostgreSQL (database.py has create_job/update_job/get_job/list_jobs, api.py uses them, schema includes jobs table). Auth tests exist in tests/test_auth.py with 17 test functions covering registration, login, protected routes, refresh, and admin access.

**Closing as already implemented.** Verified in the current codebase that all acceptance criteria are met. Jobs are persisted in PostgreSQL (database.py has create_job/update_job/get_job/list_jobs, api.py uses them, schema includes jobs table). Auth tests exist in tests/test_auth.py with 17 test functions covering registration, login, protected routes, refresh, and admin access.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#380