feat(integrations): add manual sync for Oura, Polar, Strava and Nightscout

These four were the only connected providers with no way to ask for a
sync; they ran on their scheduled pass and nothing else. Each gets a POST
sync route on the hardened Fitbit and Google Health template: session auth,
a 5-per-minute per-user bucket, and a fixed 502 on failure. No body and no
full-sync flag, because none of the four entry points has a full-history
arm to call. Polar goes through the shared legs entry point so both legs
run with the attribution rules built for them.

The Nightscout error arm is the one that matters: a base URL carries the
API token as a query parameter, so the caught message can hold the user's
secret and never reaches the response body. The classified failure is
already on the ledger, recorded with the provider's own redaction.

Connecting also starts the first sync now. The poll handler has accepted a
single-user payload since it was written and never had a producer, so a
fresh connection sat empty for up to an hour waiting for the schedule. The
Oura and Polar callbacks and the Nightscout connect route enqueue one
targeted job each, best effort, with the hourly tick still the safety net.
Strava needs none: its callback already enqueues the history backfill,
which covers the recent window.

The four poll-queue names move into their own module so a request-path
caller can name a queue without dragging the whole worker handler graph
into the request bundle, following the backfill-queue precedent. Creation,
scheduling and handler binding stay in the registrar, and the dead-queue
guard follows the declarations.
This commit is contained in:
Marc-André Bombeck committed 2026-07-25 04:43:06 +02:00
1 parent 9bbbeb805c
commit a9f1629f82
17 files changed
+874 -21

No files matched your search

@@ -18,7 +18,15 @@ import { describe, expect, it } from "vitest";
// file into domain registrars; the Nightscout / Polar / Oura queues live in the
// integration-sync registrar. The dead-queue guard follows the wiring there
// (the handler module is still concatenated for the handler-symbol assertions).
//
// v1.32.28 — the four poll-queue NAMES moved again, into
// `integration-poll-queues.ts`, so an OAuth callback can enqueue a connect-time
// first sync without importing the registrar's handler graph. The guard follows
// them: the name declarations are asserted against that module, everything else
// (allQueues membership, cron schedule, handler binding) still against the
// registrar.
const source =
readFileSync(join(__dirname, "..", "integration-poll-queues.ts"), "utf8") +
readFileSync(
join(__dirname, "..", "reminder", "register-integration-sync.ts"),
"utf8",
+27
View File
@@ -0,0 +1,27 @@
/**
* Queue names for the poll-only integration syncs.
*
* Split out of `reminder/register-integration-sync.ts` so a request-path caller
* (an OAuth callback enqueueing the first sync at connect time) can name the
* queue without importing the registrar — which would drag every worker handler
* and its transitive graph into the request bundle. Same shape as
* `STRAVA_BACKFILL_QUEUE`, which the Strava callback already imports from its
* own module.
*
* The registrar remains the single place that creates, schedules, and binds a
* handler to each of these; the values here are its source. A name declared
* here but missing from `allQueues` there is the v1.4.37 dead-queue class, and
* the queue-wiring guards read both files for exactly that reason.
*/
/** Hourly Nightscout CGM poll (:11). */
export const NIGHTSCOUT_SYNC_QUEUE = "nightscout-sync";
/** Hourly Polar AccessLink poll (:13). */
export const POLAR_SYNC_QUEUE = "polar-sync";
/** Hourly Oura Cloud poll (:15). */
export const OURA_SYNC_QUEUE = "oura-sync";
/** Hourly Strava poll (:17). */
export const STRAVA_SYNC_QUEUE = "strava-sync";
@@ -77,6 +77,12 @@ import {
type ScheduleEntry,
} from "./registrar-shared";
import { WITHINGS_ECG_SYNC_QUEUE } from "@/lib/jobs/withings-ecg-queue";
import {
NIGHTSCOUT_SYNC_QUEUE,
OURA_SYNC_QUEUE,
POLAR_SYNC_QUEUE,
STRAVA_SYNC_QUEUE,
} from "@/lib/jobs/integration-poll-queues";
import {
WithingsSyncPayload,
WithingsActivitySyncPayload,
@@ -223,8 +229,11 @@ const GOOGLE_HEALTH_OAUTH_STATE_CLEANUP_CRON = "26 3 * * *";
// pulls the recent SGV window per configured instance. :11 staggers off the
// WHOOP (:05), Fitbit (:08), and Withings sync ticks so the hourly polls don't
// pile up on one boss poll.
const NIGHTSCOUT_SYNC_QUEUE = "nightscout-sync";
//
// The four poll-queue NAMES live in `@/lib/jobs/integration-poll-queues` (see
// the import above) so an OAuth callback can enqueue a connect-time first sync
// without importing this registrar and its whole handler graph. Creation,
// scheduling, and handler binding stay here.
const NIGHTSCOUT_SYNC_CRON = "11 * * * *"; // every hour at :11
// v1.17.0 (F4) — Polar + Oura OAuth poll sync. Poll-only (one hourly tick per
// provider re-walks every connected user). :13 / :15 stagger off the other
@@ -232,16 +241,13 @@ const NIGHTSCOUT_SYNC_CRON = "11 * * * *"; // every hour at :11
// pile up on one boss poll. The queues MUST be registered in `allQueues` below
// or pg-boss never provisions them and the schedule silently no-ops (the
// v1.4.37 dead-queue class).
const POLAR_SYNC_QUEUE = "polar-sync";
const POLAR_SYNC_CRON = "13 * * * *"; // every hour at :13
const OURA_SYNC_QUEUE = "oura-sync";
const OURA_SYNC_CRON = "15 * * * *"; // every hour at :15
// v1.28.x — Strava OAuth poll sync. Poll-only (webhook deferred): one hourly
// tick re-walks every connected user. :17 staggers off the Polar (:13) / Oura
// (:15) ticks so the polls don't pile up on one boss poll. The queue MUST be
// registered in `allQueues` below or pg-boss never provisions it and the
// schedule silently no-ops (the v1.4.37 dead-queue class).
const STRAVA_SYNC_QUEUE = "strava-sync";
const STRAVA_SYNC_CRON = "17 * * * *"; // every hour at :17
// v1.30.x — daily sweep for the native OIDC handoff ledger. Handoff codes are
// single-use + 90s-lived and expiry is enforced at read, so this is pure