Repository navigation
ADFA-4838: durable REST job engine for live content (kiwix) - #253
Merged
Merged
Conversation
Phase 2 of ADFA-4832. Module-scoped, persisted job engine so a content op is owned by the dashboard process (not a socket closure) and survives a client disconnect and a dashboard restart. - jobs.ts: JobManager with a better-sqlite3 journal (jobs table), per-type Runner registry, structured progress (phase/percent/bytes-per-sec), cancellation that kills tracked children, and reconcileOnBoot() to resume interrupted jobs. - kiwix.exec.ts: kiwix runner ported from the Phase 1 socket handler — aria2 download (structured %/rate parsing) + iiab-make-kiwix-lib index + metadata cleanup + a free- space guard. aria2 flags kept in sync with the app + the socket handler. - ADR-4832 refreshed as the accepted full-Phase-2 design of record. Typechecks (tsc --noEmit). Not wired into server.ts yet (REST routes + reconcile call come next); no runtime behavior change until then.
- routes.ts: POST /api/:type/download, GET /api/:type/jobs(/:id), POST .../cancel. Stateless calls over the durable engine; clients re-attach by polling the id. - server.ts: mount express.json() + /api router, import the kiwix runner (registers it), and call jobs.reconcileOnBoot() on listen so interrupted jobs resume. - nginx: add a localhost-only /api/ proxy to :4000 (mirrors the /dashboard/ + /socket.io/ locations). Kiwix now works end-to-end over REST. maps/books runners and retiring the socket-owned job paths are the next steps. Typechecks (tsc --noEmit).
Port the remaining live-content types off the Phase 1 socket handlers onto the durable
job engine, so all three run the same way.
- Generalize the job payload: items are now arbitrary (strings for kiwix ZIMs; objects
for maps/books). RunnerContext exposes items (raw) + ids (string convenience); routes
accept { items } or { ids }.
- maps.exec.ts: tile-extract.py extract, reusing the socket handler's box validation;
structured progress (parses a % when the script prints one).
- books.exec.ts: Calibre-Web auth/CSRF + Gutenberg fetch + upload, per-book progress.
Deletion (maps/books) stays a separate op for now. Typechecks (tsc --noEmit).
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.
Phase 2 of ADFA-4832 (see
controller/docs/ADR-4832). Replaces the per-socket, kill-on-disconnect job handling with a durable, REST-driven engine.sockets/jobs.ts— module-scopedJobManagerwith abetter-sqlite3journal, a per-type Runner registry, structured progress (phase / percent / bytes-per-sec), cancellation that kills tracked children, andreconcileOnBoot()to resume interrupted jobs after a dashboard restart.sockets/kiwix.exec.ts— kiwix runner ported from the Phase 1 socket handler: aria2 download (structured %/rate) +iiab-make-kiwix-libindex + metadata cleanup + free-space guard. aria2 flags kept in sync with the app + the socket handler.routes.ts—POST /api/:type/download,GET /api/:type/jobs(/:id),POST /api/:type/jobs/:id/cancel.server.ts— mountsexpress.json()+/api, registers the kiwix runner, callsreconcileOnBoot()./api/proxy to :4000.Scope note: kiwix is migrated end-to-end here (the proven path, consumed by the app in ADFA-4840). maps/books already operate through the existing dashboard handlers; their runner migration lands with their active-management redesign. Packaging (TS→JS build + supervision) is ADFA-4839.
Typechecks (
tsc --noEmit). Ships via the Phase 2 rootfs rebuild. Needs on-device verification.