Files
HealthLog/src/lib/jobs/integration-backfill-forward.ts
T
Marc-André Bombeck 4807a70c1d refactor(jobs): declare every queue in a typed registry and load handlers on first job
The five hand-written registrars (about 5,500 lines, one 997-line function)
are replaced by `jobs/registry/`: one `defineJob` entry per queue with its
cron, schedule send options, policy, work options, lock, lane and a handler
loader. `registerJobGroup` creates, schedules, retires and binds each group
in the order the registrars used; the worker boot walks the groups and runs
their boot discovery.

Handlers load on their queue's first job. The facts a declaration needs at
boot (names, crons, concurrency, send options) moved out of the heavy job
modules into light `*-queue.ts` siblings, and their importers point there,
so loading the registry evaluates 288 modules instead of the 1,164 the
registrars pulled in. The formerly inline handlers moved verbatim into
handler modules under `jobs/reminder/`.

Fitbit's queues live in `fitbit/jobs/definitions.ts` and enter the registry
through one spread, so removing the integration later is that folder and
that line.

`tests/integration/queue-registration-parity.test.ts` proves pg-boss holds
exactly what the registrars left (queues, schedules, bindings, byte for
byte) and loads every handler once. The queue tests and the runtime guard
assert on the registry objects instead of reading registrar source.
2026-10-23 12:36:09 +02:00

28 lines
982 B
TypeScript

/**
* The handler of every full-history source queue (`whoop-backfill`,
* `strava-backfill`, the sleep repairs, ...): it forwards each job to the
* shared admission queue, where the import itself runs in the one
* cross-provider lane. The source queue keeps its per-connection singleton
* key, which is what boot discovery re-offers against.
*/
import type { Job, PgBoss } from "pg-boss";
import {
enqueueIntegrationBackfillAdmission,
type IntegrationBackfillData,
type IntegrationBackfillKind,
} from "@/lib/jobs/integration-backfill-admission";
import { jobDone, type JobOutcome } from "@/lib/jobs/job-outcome";
export function forwardToBackfillAdmission(
boss: PgBoss,
kind: IntegrationBackfillKind,
): (jobs: Job<IntegrationBackfillData>[]) => Promise<JobOutcome> {
return async (jobs) => {
for (const job of jobs) {
await enqueueIntegrationBackfillAdmission(boss, { kind, data: job.data });
}
return jobDone({ jobs: jobs.length });
};
}