feat(rest): FastAPI adapter + /jobs /healthz /metrics (spec 5) #21

Merged
goldstein merged 1 commit from feat/rest-adapter into main 2026-04-18 09:47:36 +00:00
Owner

REST routes: POST /jobs (201/200 idempotent), GET /jobs/{id}, GET /jobs?client_id&request_id, GET /healthz (3-probe + 2s pg timeout), GET /metrics (24h counters).

create_app(spawn_worker=bool) makes worker spawning opt-out; probes are DI-d for test injection.

9 integration tests pass locally; unit suite still 209. Forgejo Actions trigger is flaky; local verification is the gate.

REST routes: POST /jobs (201/200 idempotent), GET /jobs/{id}, GET /jobs?client_id&request_id, GET /healthz (3-probe + 2s pg timeout), GET /metrics (24h counters). create_app(spawn_worker=bool) makes worker spawning opt-out; probes are DI-d for test injection. 9 integration tests pass locally; unit suite still 209. Forgejo Actions trigger is flaky; local verification is the gate.
goldstein added 1 commit 2026-04-18 09:47:31 +00:00
feat(rest): FastAPI adapter + /jobs, /healthz, /metrics routes (spec §5)
All checks were successful
tests / test (push) Successful in 1m7s
tests / test (pull_request) Successful in 1m5s
e46c44f1e0
Routes:
- POST /jobs: 201 on first insert, 200 on idempotent re-submit.
- GET /jobs/{id}: full Job envelope or 404.
- GET /jobs?client_id=&request_id=: correlation lookup or 404.
- GET /healthz: {postgres, ollama, ocr}; 200 iff all ok (degraded counts
  as non-200 per spec). Postgres probe guarded by a 2 s wait_for.
- GET /metrics: pending/running counts + 24h done/error counters +
  per-use-case avg seconds. Plain JSON, no Prometheus.

create_app(spawn_worker=bool) parameterises worker spawning so tests that
only need REST pass False. Worker spawn is tolerant of the loop module not
being importable yet (Task 3.5 fills it in).

Probes are a DI bundle — production wiring swaps them in at startup
(Chunk 4); tests inject canned ok/fail callables. Session factory is also
DI'd so tests can point at a per-loop engine and sidestep the async-pg
cross-loop future issue that bit the jobs_repo fixture.

9 new integration tests; unit suite unchanged. Forgejo Actions trigger is
flaky; local verification is the gate (unit + integration green locally).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
goldstein merged commit ee023d6e34 into main 2026-04-18 09:47:36 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: goldstein/infoxtractor#21
No description provided.