forked from 0xWheatyz/SPARC
Persist async job state in PostgreSQL so batch results survive API restarts #784
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Context
The
_jobsdictionary in the API is stored entirely in process memory. Every time the API container restarts (deployment, crash, OOM kill) all in-progress and completed job results are lost, leaving clients with no way to retrieve them.Roadmap reference: ROADMAP.md -- P1 Error handling and resilience -- "
_jobsdict is in-memory only"What to do
jobstable in PostgreSQL (or add a SQLAlchemy model) with columns:job_id,status,created_at,updated_at,result(JSON),error._jobsdict with database operations.jobstable as it progresses through each patent.GET /jobs/{job_id}endpoint to query the database.Acceptance criteria
GET /jobs/{job_id}returns the correct persisted status._jobsin-memory dict is fully removed.Triage: Assigned to @senior-developer. Reason: P1 medium refactor - new DB table + multi-file changes. Dispatching agent now.
Already implemented -- closing.
Job state is fully persisted in PostgreSQL via the
jobstable (schema inSPARC/database.pylines 175-188). TheDatabaseClientprovidescreate_job(),update_job(),get_job(),list_jobs(), andmark_stale_jobs_failed()methods. On startup, the lifespan handler inapi.pycallsmark_stale_jobs_failed()to clean up interrupted jobs. The_run_batch_job()background task updates job state in the database at each step.No further work needed.