feat(jobs): persist async batch job state in PostgreSQL #34

Merged
AI-Manager merged 1 commits from feature/persist-job-state into main 2026-03-26 05:04:28 +00:00
Owner

Summary

  • Add jobs table to PostgreSQL schema for persisting async batch job state
  • Add DatabaseClient methods: create_job, update_job, get_job, list_jobs, mark_stale_jobs_failed
  • Refactor _run_batch_job and all job endpoints to read/write from the database
  • Remove in-memory _jobs dict -- job state now survives API restarts
  • On startup, any jobs in running/pending state are marked failed to avoid stuck states

Closes #8

Test plan

  • Start a batch job, restart the API, verify /jobs/{job_id} still returns the job
  • Verify jobs in running state at restart are marked failed
  • Verify /jobs list endpoint returns persisted jobs
  • Existing tests pass (9 pre-existing failures unrelated to this change)

🤖 Generated with Claude Code

## Summary - Add `jobs` table to PostgreSQL schema for persisting async batch job state - Add `DatabaseClient` methods: `create_job`, `update_job`, `get_job`, `list_jobs`, `mark_stale_jobs_failed` - Refactor `_run_batch_job` and all job endpoints to read/write from the database - Remove in-memory `_jobs` dict -- job state now survives API restarts - On startup, any jobs in `running`/`pending` state are marked `failed` to avoid stuck states Closes #8 ## Test plan - [ ] Start a batch job, restart the API, verify `/jobs/{job_id}` still returns the job - [ ] Verify jobs in `running` state at restart are marked `failed` - [ ] Verify `/jobs` list endpoint returns persisted jobs - [ ] Existing tests pass (9 pre-existing failures unrelated to this change) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
AI-Manager added 1 commit 2026-03-26 04:23:13 +00:00
- Add jobs table to database schema (job_id, status, progress, result_json, etc.)
- Add DatabaseClient methods: create_job, update_job, get_job, list_jobs
- Add mark_stale_jobs_failed() called at startup to handle interrupted jobs
- Refactor _run_batch_job and job endpoints to read/write from PostgreSQL
- Remove in-memory _jobs dict; job state now survives API restarts
- Update init_database.py to list all tables in output

Closes leeworks-agents/SPARC#8

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
AI-Manager merged commit 6fcf170d93 into main 2026-03-26 05:04:28 +00:00
Sign in to join this conversation.