Skip to content

MftScheduler

Defined in: src/mft/MftScheduler.ts:106

Runs routes on configured schedules.

Subscribes to a ScheduleRegistry, computes the next fire time for each schedule (cron or interval), and dispatches the matching route through a runner of your choice (runRoute by default, or a wrapped runner for approvals / rate limiting / circuit breaking). Observers fire on each cycle for telemetry. Tests can inject a deterministic timer via timer.

import {
ApprovalRegistry,
InMemoryAuditLog,
MftScheduler,
RouteRegistry,
ScheduleRegistry,
createApprovalGate,
runRoute,
} from "@zero-transfer/sdk";
const audit = new InMemoryAuditLog();
const approvals = new ApprovalRegistry();
const scheduler = new MftScheduler({
client,
routes: new RouteRegistry([route]),
schedules: new ScheduleRegistry([
{ id: "nightly", routeId: route.id, cron: "0 2 * * *" },
]),
runner: createApprovalGate({
registry: approvals,
approvalId: ({ route }) => `release:${route.id}`,
runner: ({ client: c, route: r, signal }) => runRoute({ client: c, route: r, signal }),
}),
onResult: ({ receipt }) => audit.record({ type: "transfer.success", receipt }),
onError: ({ error }) => audit.record({ type: "transfer.failure", error }),
});
scheduler.start();
new MftScheduler(options: MftSchedulerOptions): MftScheduler;

Defined in: src/mft/MftScheduler.ts:121

Creates a scheduler bound to a transfer client and registries.

ParameterTypeDescription
optionsMftSchedulerOptionsClient, registries, optional runner, observers, and timer hooks.

MftScheduler

get isRunning(): boolean;

Defined in: src/mft/MftScheduler.ts:132

Whether the scheduler is currently running.

boolean

start(): void;

Defined in: src/mft/MftScheduler.ts:137

Starts the scheduler. No-op when already running.

void


stop(): Promise<void>;

Defined in: src/mft/MftScheduler.ts:152

Stops the scheduler and aborts in-flight route executions.

Promise<void>

A promise that resolves once all in-flight fires have settled.