Skip to content

Commit b9fa5ab

Browse files
authored
refactor(gateway): reuse cron stream owner callback contract (#129900)
1 parent 2c9bcf3 commit b9fa5ab

1 file changed

Lines changed: 8 additions & 43 deletions

File tree

‎src/gateway/cron-stream-watchers.ts‎

Lines changed: 8 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,20 @@
11
import { resolveCronTriggerMinIntervalMs } from "../config/cron-limits.js";
22
import type { CronJob, CronJobState } from "../cron/types.js";
33
import { pruneMapToMaxSize } from "../infra/map-size.js";
4-
import type { ProcessSupervisor } from "../process/supervisor/index.js";
54
import {
65
CronStreamJobOwner,
76
isCronStreamJob,
87
type CronStreamOwnerParams,
98
type CronStreamOwnerSnapshot,
109
type CronStreamStopReason,
1110
} from "./cron-stream-job-owner.js";
12-
import type { CronStreamFireDisposition, CronStreamJob } from "./cron-stream-output.js";
11+
import type { CronStreamJob } from "./cron-stream-output.js";
1312

1413
export type { CronStreamFireDisposition } from "./cron-stream-output.js";
1514

1615
const MAX_RETIRED_COUNTER_SEEDS = 1_024;
1716
const MAX_MUTATION_EPOCHS = 1_024;
1817

19-
type Logger = {
20-
info: (obj: unknown, msg?: string) => void;
21-
warn: (obj: unknown, msg?: string) => void;
22-
};
23-
2418
type CronStreamWatchers = {
2519
reconcile: (jobs: CronJob[], enabled: boolean, triggersEnabled?: boolean) => Promise<void>;
2620
resume: () => void;
@@ -51,42 +45,13 @@ export function resolveStreamStopReason(input: {
5145
}
5246

5347
/** Supervise line-producing cron sources through one serialized owner per job. */
54-
export function createCronStreamWatchers(params: {
55-
getProcessSupervisor: () => ProcessSupervisor;
56-
/** Test seams; production uses the built-in cadence and retry schedules. */
57-
minIntervalMs?: number;
58-
retryBackoffMs?: number[];
59-
updateState: (
60-
jobId: string,
61-
patch: Partial<CronJobState>,
62-
streamScheduleKey: string,
63-
streamSourceIdentity: string,
64-
) => Promise<boolean | void>;
65-
retireSource: (
66-
jobId: string,
67-
streamScheduleKey: string,
68-
streamSourceIdentity: string,
69-
) => Promise<string | undefined>;
70-
updateCounters?: (
71-
jobId: string,
72-
counters: Pick<CronJobState, "streamDroppedBatches" | "streamCoalescedBatches">,
73-
) => Promise<void>;
74-
recordFailure: (
75-
jobId: string,
76-
error: string,
77-
patch: Partial<CronJobState>,
78-
streamScheduleKey: string,
79-
streamSourceIdentity: string,
80-
) => Promise<void>;
81-
fireBatch: (
82-
job: CronJob,
83-
batch: string,
84-
streamScheduleKey: string,
85-
streamSourceIdentity: string,
86-
) => Promise<CronStreamFireDisposition>;
87-
logger: Logger;
88-
nowMs?: () => number;
89-
}): CronStreamWatchers {
48+
export function createCronStreamWatchers(
49+
params: Omit<CronStreamOwnerParams, "minIntervalMs" | "nowMs"> & {
50+
/** Test seams; production uses the built-in cadence and retry schedules. */
51+
minIntervalMs?: number;
52+
nowMs?: () => number;
53+
},
54+
): CronStreamWatchers {
9055
const owners = new Map<string, CronStreamJobOwner>();
9156
const retiredCounterSeeds = new Map<
9257
string,

0 commit comments

Comments
 (0)