import type { CronRecord, RunRecord, ServerStateStore } from '../types/server.js'; /** A cron job that is due, with the slot it is due for. */ export interface DueCronJob extends CronRecord { /** The firing this is: the epoch millisecond of the slot, which makes the run idempotent. */ slot: number; } /** Options for the cron scheduler. */ export interface CronSchedulerOptions { /** Starts a run for a due job. */ start?: (job: DueCronJob) => Promise; /** Where jobs are recorded. Defaults to memory; share it to schedule across replicas. */ state?: ServerStateStore; /** How often due jobs are looked for, in milliseconds. Defaults to 30 seconds. */ tickMs?: number; /** Receives errors from a firing, which never stop the scheduler. */ onError?: (error: unknown, job: CronRecord) => void; /** Replaces the system clock, for tests. */ now?: () => Date; } /** * Fires scheduled runs. * * Every replica ticks, and every firing is submitted with the idempotency key `:`, so the * operation store decides which replica's submission wins and the job runs once however many * replicas are up. That is the whole coordination mechanism: no lock, no leader election, and a * replica that misses a tick simply does not win that slot. */ export declare class CronScheduler { private readonly options; private readonly state; private readonly now; private timer; private lastTick; constructor(options?: CronSchedulerOptions); /** Adds a job, validating its schedule. */ add(job: Omit & { id?: string; createdAt?: string; }): Promise; /** Reads a job. */ get(id: string): Promise; /** Every job. */ list(): Promise; /** Removes a job. */ remove(id: string): Promise; /** Starts ticking. Ticks are skipped while one is still running. */ start(): void; /** Stops ticking. */ stop(): void; /** * Fires every job due since the last tick. Call it directly to drive the scheduler from a test or * from an external scheduler such as Kubernetes. */ tick(at?: Date): Promise; } interface CronFields { minute: number[]; hour: number[]; day: number[]; month: number[]; weekday: number[]; } /** * Parses the five-field cron syntax: `*`, numbers, `a-b` ranges, `a,b` lists, and `*​/n` steps. * * Times are UTC, so a schedule means the same thing on every replica whatever its timezone is set to. */ export declare function parseCron(expression: string): CronFields; export {};