interface IScheduler
Since 0.1.0

In-process job scheduler.

Supports cron expressions (5-field, UTC), fixed-interval recurring jobs, and one-shot delayed jobs. Execution is process-local and time-driven (no durable persistence).

Methods

cron<T = unknown>(
name: string,
expression: string,
handler: SchedulerJobHandler<T>,
options?: ScheduleOptions<T>
): Promise<void>

Schedule a recurring job using a 5-field cron expression (UTC).

every<T = unknown>(
name: string,
intervalMs: number,
handler: SchedulerJobHandler<T>,
options?: ScheduleOptions<T>
): Promise<void>

Schedule a recurring job that fires every intervalMs milliseconds.

delay<T = unknown>(
name: string,
delayMs: number,
handler: SchedulerJobHandler<T>,
options?: ScheduleOptions<T>
): Promise<void>

Schedule a one-shot delayed job.

The job fires once after delayMs and is then auto-removed.

pause(name: string): Promise<void>

Pause a scheduled job without dropping its configuration.

Idempotent — calling pause on an already-paused job is a no-op.

resume(name: string): Promise<void>

Resume a paused job.

For cron jobs the next fire is computed from now(). For every jobs the next fire is the next epoch grid boundary of the interval — (floor(now / intervalMs) + 1) * intervalMs — NOT a full interval after now(): grid alignment is what makes replicas started at different instants agree on fire times and distributed-lock slot keys (M70l X10-2). Breaking vs 0.1.0-alpha.8: the released contract stated the interval "restarts from now"; the fire may now come sooner than one full interval after resume (never later). For delay jobs the full original delayMs is re-armed from now().

Idempotent — calling resume on a running job is a no-op.

remove(name: string): Promise<void>

Remove a scheduled job entirely.

getNextRun(name: string): Promise<number>

Return the next scheduled fire time as epoch milliseconds.

Usage

import { type IScheduler } from "common/src/index.ts";