fix(api): job search status refresh - #421
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
|
||
| if body.refresh_status: | ||
| refreshed_jobs = [] | ||
| for job in jobs: |
There was a problem hiding this comment.
Hm yeah, this can get expensive if there are many jobs in the query (and many of them to be refreshed)
I think in terms of pattern we should move away entirely on doing these implicit updates on user read requests and have a background task take care of it.
Here is a brief summary of the proposal. You could start to use this as a basis for a new PR or I could work on it next week
Move ingestion out of the request path. GET /jobs/{id} becomes a pure SELECT; a single background process is the only writer of job state and the only component aware of both executorlib and the DB.
- Mechanism: reconciliation loop scanning non-terminal jobs (durable, restart-safe), optionally plus
add_done_callback()for lower latency. - Contract: the worker watches executorlib's
cache_directoryfor completed*_o.h5outputs, keyed bycache_key. - States:
SUBMITTED → RUNNING → FINISHED → INGESTING → INGESTED(+ failure states). Separating "executor finished" from "results in DB" is what fixes the wrong-status queries. - Safety: claim via compare-and-swap or
[SKIP LOCKED](https://www.postgresql.org/docs/current/sql-select.html#SQL-FOR-UPDATE-SHARE), idempotent upserts, retry limit. - Deployment: separate process, or FastAPI [lifespan](https://fastapi.tiangolo.com/advanced/events/) behind a
pg_advisory_lock(otherwise it runs once per uvicorn worker).
Trade-off: status is stale by at most one poll interval — correct-but-delayed instead of fast-but-wrong.
There was a problem hiding this comment.
So we scratch this PR, or do you want to approve/merge this in the meantime?
There was a problem hiding this comment.
you can merge it if you want, we just need to make sure to remove this logic again since it can potentially stall the process for quite a while
Situation
runningstates, while per-job status checks already showedcompleted.Changes
refresh_statustoPOST /jobs:search(default:true) to refreshrunningjobs before returning matches.search_jobssemantics (snapshot vs refresh, tag AND behavior) in API schema/docstrings.search_jobsfor listing/filtering andget_job_statusfor live status checks, without implying automatic polling.Validation