feat(sketch-db): Phase 5d — HTTP endpoints for backfill lifecycle - #30
Merged
Merged
Conversation
Operator + controller-facing HTTP surface for §10.2 backfill jobs.
Endpoints return a stable JSON shape so the DC controller can
POST jobs + poll progress without attaching a debugger, and the
`/jobs/:id` detail is the same data Phase 5f's coverage tracker
will consult.
## New endpoints
| Method | Path | Purpose |
|---|---|---|
| POST | `/api/v1/db/backfill` | Create a queued job. Body `{agg_id, start_ms, end_ms, source, windows_total}`. Returns 201 with `{job_id}`. |
| GET | `/api/v1/db/backfill/jobs` | List, optional `?status=queued|running|complete|failed|cancelled|all` filter. Sorted by job_id. |
| GET | `/api/v1/db/backfill/jobs/:id`| Detail (including `progress`, `windows_done`, timestamps, and any `error_message`). |
| DELETE | `/api/v1/db/backfill/jobs/:id`| Cancel non-terminal job. 200 on success, 404 unknown, 409 if already terminal. |
Consistent with the §15.2/§15.3 endpoints from PR #23 / PR #25:
- 503 when `HttpServer` wasn't built with `with_backfill_registry`.
- 400 on malformed body or inverted range.
- Response JSON tagged `{status: "success"|"error", ...}`.
## Wire-up
* `HttpServer` gains `with_backfill_registry()` alongside
`with_schemas()` / `with_hot_reload_config()`.
* `AppState` carries an `Option<Arc<BackfillRegistry>>` so each
handler can bail to 503 cleanly when the registry isn't
attached.
* `main.rs` always creates a fresh `Arc<BackfillRegistry>` and
attaches it — no CLI flag required. Without Phase 5e's worker
pool, jobs stay `Queued` forever but are still visible + can be
cancelled, which is useful shadow-mode for validating the DC
controller's REFRESH dispatch logic before the worker arrives.
## Test plan
- [x] 5 new integration tests:
* Full lifecycle: POST → GET one → GET list → GET filtered lists
(both `queued` matches and `running` is zero) → DELETE cancels
→ second DELETE is 409.
* POST with inverted range → 400.
* GET on unknown id → 404.
* All endpoints return 503 when no registry is attached.
* GET `jobs?status=junk` → 400.
- [x] 625 lib tests pass (up from 620).
- [x] clippy + fmt clean.
## Next phase
5e: real `WindowProcessor` that builds the target sketch from raw
samples and writes per-window precomputes into the store through
the §6.3 schema barrier. When 5e merges, POSTing a backfill job
will actually rebuild history.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Operator + controller-facing HTTP surface for §10.2 backfill jobs.
/api/v1/db/backfill{job_id}/api/v1/db/backfill/jobs?status=filter/api/v1/db/backfill/jobs/:id/api/v1/db/backfill/jobs/:idConsistent shape with PR #23 / PR #25: 503 when registry isn't attached, 400 on bad body / inverted range, 404/409 as appropriate. JSON response wrapped in
{status: "success"|"error", ...}.Wire-up
HttpServer::with_backfill_registry()builder.main.rsalways creates a freshArc<BackfillRegistry>and attaches it — no CLI flag needed. Without Phase 5e's worker, jobs stayQueuedbut are inspectable + cancelable (shadow-mode for the DC controller's REFRESH dispatch logic).Test plan
Next phase
5e: real
WindowProcessorbuilds target sketch from raw samples + writes per-window precomputes through the §6.3 barrier. After 5e, POSTing a job actually rebuilds history.🤖 Generated with Claude Code