From 8f545af3ec74273ca7651e32a252e037c45278d4 Mon Sep 17 00:00:00 2001 From: jackshim415 Date: Thu, 19 Nov 2026 08:38:05 -0800 Subject: [PATCH 1/3] Keep scheduled worker runs continuous during competition dates Six-hour Cron starts enter the minute-level event loop on local competition dates, then drain and exit when events finish. This makes the November rollout safe without a manual event-day mode switch. Record the production baseline and private preview verification setup. --- .railway/config.test.mjs | 27 ++++++ .railway/railway.ts | 9 +- apps/worker/README.md | 9 ++ apps/worker/index.ts | 7 +- apps/worker/src/scheduled-window.ts | 49 ++++++++++ apps/worker/src/worker.ts | 4 +- apps/worker/test/scheduled-window.test.ts | 109 ++++++++++++++++++++++ docs/worker-batch-rollout.md | 49 ++++++++-- 8 files changed, 250 insertions(+), 13 deletions(-) create mode 100644 apps/worker/src/scheduled-window.ts create mode 100644 apps/worker/test/scheduled-window.test.ts diff --git a/.railway/config.test.mjs b/.railway/config.test.mjs index fa36c10d..deb70a5b 100644 --- a/.railway/config.test.mjs +++ b/.railway/config.test.mjs @@ -118,3 +118,30 @@ test("offseason cron uses a finite batch without a health listener or restarts", assert.equal(worker.deploy.cronSchedule, undefined); assert.equal(worker.deploy.healthcheckPath, "/health"); }); + +test("scheduled event mode requires six-hour starts and retains automatic competition windows", () => { + const previousCron = process.env.RAILWAY_WORKER_CRON; + const previousMode = process.env.RAILWAY_WORKER_MODE; + try { + process.env.RAILWAY_WORKER_MODE = "scheduled"; + process.env.RAILWAY_WORKER_CRON = "0 18 * * *"; + assert.throws( + () => config(createRailwayContext({ environment: "production" })), + /six-hour Cron/, + ); + process.env.RAILWAY_WORKER_CRON = "0 */6 * * *"; + const worker = config( + createRailwayContext({ environment: "production" }), + ).resources.find((r) => r.name === "worker"); + assert.deepEqual(worker.variables.WORKER_MODE, { + type: "literal", + value: "scheduled", + }); + assert.equal(worker.deploy.cronSchedule, "0 */6 * * *"); + } finally { + if (previousCron === undefined) delete process.env.RAILWAY_WORKER_CRON; + else process.env.RAILWAY_WORKER_CRON = previousCron; + if (previousMode === undefined) delete process.env.RAILWAY_WORKER_MODE; + else process.env.RAILWAY_WORKER_MODE = previousMode; + } +}); diff --git a/.railway/railway.ts b/.railway/railway.ts index 43cfe2d1..767673eb 100644 --- a/.railway/railway.ts +++ b/.railway/railway.ts @@ -143,11 +143,18 @@ export default defineRailway((ctx) => { // Opt in only after preview validation; merging keeps the current service running. const workerCron = process.env.RAILWAY_WORKER_CRON?.trim(); + const cronMode = process.env.RAILWAY_WORKER_MODE ?? "batch"; + if (workerCron && !["batch", "scheduled"].includes(cronMode)) { + throw new Error("RAILWAY_WORKER_MODE must be batch or scheduled"); + } + if (workerCron && cronMode === "scheduled" && workerCron !== "0 */6 * * *") { + throw new Error("Scheduled event mode requires six-hour Cron: 0 */6 * * *"); + } const worker = service("worker", { source: source("/"), env: { ...keep("DATABASE_URL", "TBA_KEY", "WORKER_CONCURRENCY"), - WORKER_MODE: workerCron ? "batch" : "continuous", + WORKER_MODE: workerCron ? cronMode : "continuous", }, build: { builder: "DOCKERFILE", diff --git a/apps/worker/README.md b/apps/worker/README.md index faa060c7..42e4814c 100644 --- a/apps/worker/README.md +++ b/apps/worker/README.md @@ -330,3 +330,12 @@ scrubs their payloads at day thirty. API startup creates no import or cleanup timers and needs no TBA key. Read-time report and verification expiry checks stay in the API. Import ownership overlaps LVT-335; resource/pool tuning remains with LVT-376. See [batch rollout](../../docs/worker-batch-rollout.md) before cutover. + + +`WORKER_MODE=scheduled` combines six-hour external Cron with automatic event-day +continuous runs. Outside competition dates it exits after the batch. On an event's +local dates it keeps the minute-level loop until all current events finish, then +exits so later Cron executions return to batches. Use only with six-hour Cron; +daily starts cannot guarantee a start before the local morning. IaC selects this +mode with the local input `RAILWAY_WORKER_MODE=scheduled` alongside +`RAILWAY_WORKER_CRON='0 */6 * * *'`. No Railway credential is needed by Worker. diff --git a/apps/worker/index.ts b/apps/worker/index.ts index 395d010e..b3c3bf88 100644 --- a/apps/worker/index.ts +++ b/apps/worker/index.ts @@ -1,6 +1,7 @@ import { db } from "./src/db"; import { tba } from "./src/tba"; import { runBatch, runWorker } from "./src/worker"; +import { runScheduledWindow } from "./src/scheduled-window"; import { createHealthApp, healthPort } from "./src/server"; // Validate the provider configuration before starting any background work. @@ -11,8 +12,8 @@ const stop = () => shutdown.abort(); let lastReconciledAt = 0; const mode = process.env.WORKER_MODE ?? "continuous"; -if (!["batch", "continuous"].includes(mode)) - throw new Error("WORKER_MODE must be batch or continuous"); +if (!["batch", "continuous", "scheduled"].includes(mode)) + throw new Error("WORKER_MODE must be batch, scheduled or continuous"); const port = healthPort(); const concurrency = Number(process.env.WORKER_CONCURRENCY ?? 2); @@ -34,6 +35,8 @@ try { // Batch has no listener or readiness queries between windows. if (mode === "batch") { await runBatch(db, shutdown.signal, concurrency); + } else if (mode === "scheduled") { + await runScheduledWindow(db, shutdown.signal, concurrency); } else { // Migrations are owned by the release/API service. await db.$queryRaw`SELECT 1 FROM "ImportJob", "FetchState", "TournamentGap" LIMIT 0`; diff --git a/apps/worker/src/scheduled-window.ts b/apps/worker/src/scheduled-window.ts new file mode 100644 index 00000000..18697e20 --- /dev/null +++ b/apps/worker/src/scheduled-window.ts @@ -0,0 +1,49 @@ +import type { PrismaClient } from "@lovat/db"; +import { day, tournamentCadence } from "./schedule"; +import { runBatch, runWorker } from "./worker"; + +export async function hasCompetitionDates(db: PrismaClient, now = new Date()) { + // The date columns are UTC midnights, while phase boundaries are event-local. + const events = await db.tournament.findMany({ + where: { + startDate: { lte: new Date(now.getTime() + day) }, + endDate: { gte: new Date(now.getTime() - 2 * day) }, + }, + select: { startDate: true, endDate: true, timezone: true }, + }); + return events.some( + (event) => tournamentCadence(event, now).phase === "active", + ); +} + +/** Six-hour Cron starts before local 07:00; active dates keep the run alive. */ +export async function runScheduledWindow( + db: PrismaClient, + signal: AbortSignal, + concurrency = 2, + dependencies = { hasCompetitionDates, runBatch, runWorker }, +) { + try { + if (signal.aborted) return; + if (!(await dependencies.hasCompetitionDates(db))) { + await dependencies.runBatch(db, signal, concurrency); + // Catalog imports can discover an event which is already in progress. + if (signal.aborted || !(await dependencies.hasCompetitionDates(db))) + return; + } + + console.info(JSON.stringify({ event: "window.continuous" })); + const finished = new AbortController(); + await dependencies.runWorker( + db, + AbortSignal.any([signal, finished.signal]), + concurrency, + async () => { + if (!(await dependencies.hasCompetitionDates(db))) finished.abort(); + }, + ); + console.info(JSON.stringify({ event: "window.drained" })); + } finally { + await db.$disconnect(); + } +} diff --git a/apps/worker/src/worker.ts b/apps/worker/src/worker.ts index 7fedc4d5..799611d7 100644 --- a/apps/worker/src/worker.ts +++ b/apps/worker/src/worker.ts @@ -20,7 +20,7 @@ export async function runWorker( db: PrismaClient, signal: AbortSignal, concurrency = 2, - onReconciled: () => void = () => {}, + onReconciled: () => void | Promise = () => {}, ) { if ( !Number.isSafeInteger(concurrency) || @@ -34,7 +34,7 @@ export async function runWorker( while (!signal.aborted) { try { await reconcileSchedule(db); - onReconciled(); + await onReconciled(); } catch { console.error("Schedule reconciliation failed; retrying in 30 seconds"); } diff --git a/apps/worker/test/scheduled-window.test.ts b/apps/worker/test/scheduled-window.test.ts new file mode 100644 index 00000000..a6d4cd89 --- /dev/null +++ b/apps/worker/test/scheduled-window.test.ts @@ -0,0 +1,109 @@ +import { expect, test } from "bun:test"; +import type { PrismaClient } from "@lovat/db"; +import { + hasCompetitionDates, + runScheduledWindow, +} from "../src/scheduled-window"; + +const event = { + startDate: new Date("2026-11-21Z"), + endDate: new Date("2026-11-21Z"), + timezone: "America/Chicago", +}; +test("competition windows include local midnight and the last day after UTC midnight", async () => { + const db = { + tournament: { findMany: async () => [event] }, + } as unknown as PrismaClient; + expect(await hasCompetitionDates(db, new Date("2026-11-21T05:59Z"))).toBe( + false, + ); + expect(await hasCompetitionDates(db, new Date("2026-11-21T06:00Z"))).toBe( + true, + ); + expect(await hasCompetitionDates(db, new Date("2026-11-22T05:59Z"))).toBe( + true, + ); + expect(await hasCompetitionDates(db, new Date("2026-11-22T06:00Z"))).toBe( + false, + ); +}); + +test("non-competition windows run a finite batch and disconnect", async () => { + let batches = 0; + let disconnected = false; + const db = { + $disconnect: async () => { + disconnected = true; + }, + } as unknown as PrismaClient; + await runScheduledWindow(db, new AbortController().signal, 2, { + hasCompetitionDates: async () => false, + runBatch: async () => { + batches++; + }, + runWorker: async () => { + throw new Error("unexpected continuous mode"); + }, + }); + expect(batches).toBe(1); + expect(disconnected).toBe(true); +}); + +test("competition windows keep minute polling until all event-local dates finish, then drain", async () => { + let checks = 0; + let disconnected = false; + const db = { + $disconnect: async () => { + disconnected = true; + }, + } as unknown as PrismaClient; + await runScheduledWindow(db, new AbortController().signal, 2, { + hasCompetitionDates: async () => ++checks < 3, + runBatch: async () => { + throw new Error("unexpected batch"); + }, + runWorker: async (_db, signal, _concurrency, onReconciled) => { + await onReconciled?.(); + expect(signal.aborted).toBe(false); + await onReconciled?.(); + expect(signal.aborted).toBe(true); + expect(disconnected).toBe(false); + }, + }); + expect(disconnected).toBe(true); +}); + +test("calendar query failure disconnects instead of starting stale event mode", async () => { + let disconnected = false; + const db = { + $disconnect: async () => { + disconnected = true; + }, + } as unknown as PrismaClient; + await expect( + runScheduledWindow(db, new AbortController().signal, 2, { + hasCompetitionDates: async () => { + throw new Error("database unavailable"); + }, + runBatch: async () => {}, + runWorker: async () => {}, + }), + ).rejects.toThrow("database unavailable"); + expect(disconnected).toBe(true); +}); + +test("a catalog batch discovering today's event immediately enters continuous mode", async () => { + let discovered = false; + let continuous = false; + const db = { $disconnect: async () => {} } as unknown as PrismaClient; + await runScheduledWindow(db, new AbortController().signal, 2, { + hasCompetitionDates: async () => discovered, + runBatch: async () => { + discovered = true; + }, + runWorker: async () => { + continuous = true; + }, + }); + expect(continuous).toBe(true); +}); diff --git a/docs/worker-batch-rollout.md b/docs/worker-batch-rollout.md index 280a893d..8bcfcade 100644 --- a/docs/worker-batch-rollout.md +++ b/docs/worker-batch-rollout.md @@ -32,14 +32,21 @@ daily season/district/maintenance work share each batch; shorter queue intervals never wake a stopped process. Failures wait until the next external window once their retry delay has elapsed. If urgent, trigger a manual batch after that delay. -Schedule both calendar cutovers before enabling Cron: enter continuous mode before -the earliest event's local morning, and restore four/daily windows after the last -event's local end. The application automatically slows job recurrence after an -event, but **does not change Railway's operating mode or Cron schedule**. Until an -operator or off-process orchestrator has scheduled and verified both transitions, -keep continuous mode. A five-minute Cron cannot provide minute-level freshness. -New catalog child jobs wait for the next snapshot; bootstrap with an additional -manual batch before switching API traffic or entering competition mode. +For automatic competition transitions, apply both +`RAILWAY_WORKER_CRON='0 */6 * * *'` and `RAILWAY_WORKER_MODE=scheduled`. +Each scheduled execution checks event-local calendar dates. Outside competition +it drains one finite batch; during competition it retains the continuous planner +and minute-level consumers until all current event dates finish, then drains and +exits. Six-hour starts occur before local 07:00 for every timezone. The planner +rechecks calendar state every 30 seconds. Railway skips overlapping scheduled +starts while this execution is active. A batch that discovers an already-active +event immediately enters continuous mode. Database failure during initial calendar +inspection fails the process rather than guessing the operating mode. + +This scheduled mode needs no Railway API credential in the worker. Keep the +six-hour schedule throughout upcoming/recent event windows; daily batch mode is +only appropriate when the calendar has no nearby events. IaC rejects daily Cron +with scheduled event mode. Bootstrap catalogs before accepting competition traffic. Railway requires Cron processes to close connections and exit; running jobs can cause later scheduled starts to be skipped. See the [Cron documentation](https://docs.railway.com/cron-jobs). @@ -118,3 +125,29 @@ No sleep or Cron settings were applied by this change. Actual sleep windows, billing impact, cold-start measurements, demand-selected timing and scheduled production cutovers remain unverified; LVT-382 must remain open until those operational gates are met. + + +## Rollout audit — 2026-11-19 + +Production Postgres already has `sleepApplication=true`; current Worker has no +Cron and runs continuously. There were no pre-existing staged production changes. +Postgres baseline (24 hours, 1,441 samples): average 1.3616 GB, current 1.7921 GB, +maximum 2.0669 GB. Baseline successful HTTP responses in a 501-request sample +(2026-11-18 20:01 through 2026-11-19 16:07 UTC): median 122 ms, p95 391 ms. +These are warm/mixed observations, not cold-start measurements or savings. + +The production calendar contains `2026mmr` on November 21 in America/Chicago; +use six-hour scheduled mode, not daily-only batches. Maintenance completed in +production at 16:20 UTC after a retry. Existing queue errors: 28 presentation, +five match, and one global-team job; durable retries must be preserved through +cutover. Postgres has WAL archiving enabled, archive timeout 60 seconds, +checkpoint timeout 300 seconds, and TCP keepalive idle 7,200 seconds. Audit WAL +archive traffic as a possible remaining wake source during the sleep trial. + +Verification environment: `lvt-382-verification` +(`a0886b55-635a-488f-aad1-2074b73111c0`), with fresh credentials and a dedicated +500 MB volume. It contains no production data, backup credentials or archives. +Railway required dashboard two-factor verification to apply its initial services. +Do not expose its database through a public TCP proxy; run the checks from the +private service network. Actual sleep/cold-start evidence and production Cron +activation are still pending this verification. From 7ad4d4dfcd66aaff491bf232bb13b5e8871c70ed Mon Sep 17 00:00:00 2001 From: jackshim415 Date: Thu, 19 Nov 2026 08:44:43 -0800 Subject: [PATCH 2/3] Stop batch claims when catalog work discovers active events --- apps/worker/src/scheduled-window.ts | 11 ++++++++++- apps/worker/src/worker.ts | 2 ++ apps/worker/test/scheduled-window.test.ts | 18 ++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/apps/worker/src/scheduled-window.ts b/apps/worker/src/scheduled-window.ts index 18697e20..ce9b54e5 100644 --- a/apps/worker/src/scheduled-window.ts +++ b/apps/worker/src/scheduled-window.ts @@ -26,7 +26,16 @@ export async function runScheduledWindow( try { if (signal.aborted) return; if (!(await dependencies.hasCompetitionDates(db))) { - await dependencies.runBatch(db, signal, concurrency); + const discovered = new AbortController(); + await dependencies.runBatch( + db, + AbortSignal.any([signal, discovered.signal]), + concurrency, + undefined, + async () => { + if (await dependencies.hasCompetitionDates(db)) discovered.abort(); + }, + ); // Catalog imports can discover an event which is already in progress. if (signal.aborted || !(await dependencies.hasCompetitionDates(db))) return; diff --git a/apps/worker/src/worker.ts b/apps/worker/src/worker.ts index 799611d7..7ab31109 100644 --- a/apps/worker/src/worker.ts +++ b/apps/worker/src/worker.ts @@ -67,6 +67,7 @@ export async function runBatch( signal: AbortSignal, concurrency = 2, dependencies = { reconcileSchedule, runNextJob }, + onJobSettled: () => Promise = async () => {}, ) { const startedAt = Date.now(); try { @@ -100,6 +101,7 @@ export async function runBatch( await dependencies.runNextJob(db, undefined, { cutoff, id: job.id }) ) processed++; + await onJobSettled(); } }), ); diff --git a/apps/worker/test/scheduled-window.test.ts b/apps/worker/test/scheduled-window.test.ts index a6d4cd89..35e4b518 100644 --- a/apps/worker/test/scheduled-window.test.ts +++ b/apps/worker/test/scheduled-window.test.ts @@ -107,3 +107,21 @@ test("a catalog batch discovering today's event immediately enters continuous mo }); expect(continuous).toBe(true); }); + +test("catalog discovery stops new batch claims before draining the snapshot backlog", async () => { + let active = false; + let entered = false; + const db = { $disconnect: async () => {} } as unknown as PrismaClient; + await runScheduledWindow(db, new AbortController().signal, 2, { + hasCompetitionDates: async () => active, + runBatch: async (_db, signal, _concurrency, _deps, settled) => { + active = true; + await settled?.(); + expect(signal.aborted).toBe(true); + }, + runWorker: async () => { + entered = true; + }, + }); + expect(entered).toBe(true); +}); From 02b28d75d1ea365002ed4e136628bfb3ad086244 Mon Sep 17 00:00:00 2001 From: jackshim415 Date: Thu, 19 Nov 2026 08:48:50 -0800 Subject: [PATCH 3/3] Persist the verified event-aware production schedule in IaC --- .railway/README.md | 4 ++-- .railway/config.test.mjs | 42 +++++++++++++++++++++++++++++++----- .railway/railway.ts | 10 ++++++--- docs/worker-batch-rollout.md | 12 ++++++----- 4 files changed, 53 insertions(+), 15 deletions(-) diff --git a/.railway/README.md b/.railway/README.md index 1c853315..c6b40d6c 100644 --- a/.railway/README.md +++ b/.railway/README.md @@ -77,6 +77,6 @@ API retains the private database migration/start command and staging's 2 CPU / See [Railway's IaC migration guide](https://docs.railway.com/infrastructure-as-code#migrating-from-config-as-code). For finite offseason batches, see [Worker batch rollout](../docs/worker-batch-rollout.md). -`RAILWAY_WORKER_CRON='0 18 * * *'` is an opt-in local plan/apply input; omitting -it keeps/restores continuous mode. Merging this configuration does not enable +`RAILWAY_WORKER_CRON='0 18 * * *'` is an opt-in local plan/apply input; production defaults to six-hour event-aware windows after the rollout. An +explicit empty `RAILWAY_WORKER_CRON` restores continuous mode. Merging this configuration does not enable Cron or PostgreSQL Serverless. diff --git a/.railway/config.test.mjs b/.railway/config.test.mjs index deb70a5b..5365a36e 100644 --- a/.railway/config.test.mjs +++ b/.railway/config.test.mjs @@ -23,7 +23,9 @@ for (const environment of ["production", "staging"]) { assert.notEqual(resource.deploy.sleepApplication, true); assert.equal( resource.deploy.restartPolicyType ?? "ON_FAILURE", - "ON_FAILURE", + resource.name === "worker" && environment === "production" + ? "NEVER" + : "ON_FAILURE", ); // Keep source connections and credential values during adoption. assert.equal(resource.source.repo, "HighlanderRobotics/lovat"); @@ -38,7 +40,11 @@ for (const environment of ["production", "staging"]) { assert.deepEqual( value, resource.name === "worker" && name === "WORKER_MODE" - ? { type: "literal", value: "continuous" } + ? { + type: "literal", + value: + environment === "production" ? "scheduled" : "continuous", + } : { type: "preserve" }, ); } @@ -56,7 +62,14 @@ for (const environment of ["production", "staging"]) { : undefined, ); const worker = service("worker"); - assert.equal(worker.deploy.healthcheckPath, "/health"); + assert.equal( + worker.deploy.healthcheckPath, + environment === "production" ? undefined : "/health", + ); + assert.equal( + worker.deploy.cronSchedule, + environment === "production" ? "0 */6 * * *" : undefined, + ); assert.equal(worker.deploy.drainingSeconds, 60); assert.equal(worker.deploy.startCommand, "bun index.ts"); assert.deepEqual(worker.deploy.multiRegionConfig, { @@ -115,8 +128,8 @@ test("offseason cron uses a finite batch without a health listener or restarts", const worker = config( createRailwayContext({ environment: "production" }), ).resources.find((r) => r.name === "worker"); - assert.equal(worker.deploy.cronSchedule, undefined); - assert.equal(worker.deploy.healthcheckPath, "/health"); + assert.equal(worker.deploy.cronSchedule, "0 */6 * * *"); + assert.equal(worker.deploy.healthcheckPath, undefined); }); test("scheduled event mode requires six-hour starts and retains automatic competition windows", () => { @@ -145,3 +158,22 @@ test("scheduled event mode requires six-hour starts and retains automatic compet else process.env.RAILWAY_WORKER_MODE = previousMode; } }); + +test("an explicit empty Cron safely restores continuous production mode", () => { + const previous = process.env.RAILWAY_WORKER_CRON; + process.env.RAILWAY_WORKER_CRON = ""; + try { + const worker = config( + createRailwayContext({ environment: "production" }), + ).resources.find((r) => r.name === "worker"); + assert.equal(worker.deploy.cronSchedule, undefined); + assert.equal(worker.deploy.healthcheckPath, "/health"); + assert.deepEqual(worker.variables.WORKER_MODE, { + type: "literal", + value: "continuous", + }); + } finally { + if (previous === undefined) delete process.env.RAILWAY_WORKER_CRON; + else process.env.RAILWAY_WORKER_CRON = previous; + } +}); diff --git a/.railway/railway.ts b/.railway/railway.ts index 767673eb..68939107 100644 --- a/.railway/railway.ts +++ b/.railway/railway.ts @@ -141,9 +141,13 @@ export default defineRailway((ctx) => { }, }); - // Opt in only after preview validation; merging keeps the current service running. - const workerCron = process.env.RAILWAY_WORKER_CRON?.trim(); - const cronMode = process.env.RAILWAY_WORKER_MODE ?? "batch"; + // Production uses event-aware windows. An explicit empty Cron restores continuous mode. + const configuredCron = process.env.RAILWAY_WORKER_CRON; + const workerCron = + configuredCron?.trim() ?? (production ? "0 */6 * * *" : undefined); + const cronMode = + process.env.RAILWAY_WORKER_MODE ?? + (production && configuredCron === undefined ? "scheduled" : "batch"); if (workerCron && !["batch", "scheduled"].includes(cronMode)) { throw new Error("RAILWAY_WORKER_MODE must be batch or scheduled"); } diff --git a/docs/worker-batch-rollout.md b/docs/worker-batch-rollout.md index 8bcfcade..1b5bfaae 100644 --- a/docs/worker-batch-rollout.md +++ b/docs/worker-batch-rollout.md @@ -3,8 +3,9 @@ ## Implemented behavior LVT-382 adds finite batch execution, durable maintenance, structured job logs and -an opt-in Railway Cron configuration. No schema migration is required. Merging -does not enable database sleeping or change the running worker to Cron. API-owned +an opt-in Railway Cron configuration. No schema migration is required. The production IaC graph defaults to six-hour +scheduled mode; applying the reviewed graph activates Cron. Merging alone does +not apply infrastructure or enable database sleeping. API-owned TBA imports and periodic maintenance are removed; deploy the worker first and verify its maintenance job before deploying the API. @@ -13,8 +14,9 @@ verify its maintenance job before deploying the API. Use the existing `.railway/railway.ts` named partial and authenticated CLI linked to the intended environment. `RAILWAY_WORKER_CRON` is a **local IaC input** which sets Worker `WORKER_MODE=batch`, Cron, and restart policy NEVER, and removes the -continuous health check. Supply the same input for every plan/apply; otherwise -the graph returns the worker to continuous mode and clears Cron. Confirm that the +continuous health check. Production defaults to six-hour scheduled mode. Set `RAILWAY_WORKER_CRON` to an +explicit empty string to restore continuous mode. Other environments retain +continuous mode unless a Cron input is supplied. Confirm that the plan clears the old health check/Cron/restart settings before applying. Never run both a second polling worker and the Cron worker when trying to measure sleep. @@ -104,7 +106,7 @@ Use DB/platform metrics for actual activity, sleep, connection and cost evidence Alert on missing scheduled completion, repeated retries, overdue jobs and active matches older than their event cadence. Logs contain no scouting payloads. -Rollback scheduling by unsetting `RAILWAY_WORKER_CRON`, reviewing/applying the +Rollback scheduling by setting `RAILWAY_WORKER_CRON=''`, reviewing/applying the continuous graph and verifying `/health` plus fresh matches. Disable database sleep if cold-start correctness regresses. Keep the new API import ownership; restoring old API timers alongside Worker duplicates ingestion. Queue explicit