From d1545cf554abb984f4240360e1c41a6f3696fdb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Fri, 23 Oct 2026 22:13:00 +0200 Subject: [PATCH] refactor(jobs): keep the lane's hold grace private to the lane --- src/lib/jobs/__tests__/heavy-lane.test.ts | 7 ++++--- src/lib/jobs/heavy-lane.ts | 7 +++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/lib/jobs/__tests__/heavy-lane.test.ts b/src/lib/jobs/__tests__/heavy-lane.test.ts index ea90f59c6..81caf0c74 100644 --- a/src/lib/jobs/__tests__/heavy-lane.test.ts +++ b/src/lib/jobs/__tests__/heavy-lane.test.ts @@ -17,7 +17,7 @@ vi.mock("@/lib/observability/container-memory", () => ({ import { emitSignal } from "@/lib/logging/signal"; import { heavyLane, - LANE_HOLD_GRACE_SECONDS, + LANE_DEFER_SECONDS, LANE_WAIT_WARN_MS, laneWanted, } from "../heavy-lane"; @@ -309,8 +309,9 @@ describe("a holder that never finishes", () => { now, )([{ ...job("restore"), expireInSeconds: 21600 } as TestJob]); - // Inside the backup's expiry and grace, the restore waits its turn. - clock = start + (7200 + LANE_HOLD_GRACE_SECONDS) * 1000; + // Inside the backup's expiry and the grace of one deferral after it, the + // restore waits its turn. + clock = start + (7200 + LANE_DEFER_SECONDS) * 1000; await tryRestore(); expect(restore).not.toHaveBeenCalled(); expect(back.map((b) => b.queue)).toEqual(["backup-restore"]); diff --git a/src/lib/jobs/heavy-lane.ts b/src/lib/jobs/heavy-lane.ts index 93ae7f85a..5fb17e3c6 100644 --- a/src/lib/jobs/heavy-lane.ts +++ b/src/lib/jobs/heavy-lane.ts @@ -113,8 +113,11 @@ export const LANE_YIELD_DELAY_SECONDS = 2 * LANE_DEFER_SECONDS; /** How long a job may stand in line before the wait is reported at `warn`. */ export const LANE_WAIT_WARN_MS = 2 * 60 * 60 * 1000; -/** How long past its jobs' expiry a holder keeps the lane before it is taken. */ -export const LANE_HOLD_GRACE_SECONDS = LANE_DEFER_SECONDS; +/** + * How long past its jobs' expiry a holder keeps the lane before it is taken: + * one deferral, so a job that went back just before the expiry finds it. + */ +const LANE_HOLD_GRACE_SECONDS = LANE_DEFER_SECONDS; /** What one trip back to the queue did. */ export interface LaneDeferral {