Skip to content
Français

runSchedules

import { runSchedules } from "@elie-laloum/outpost";

Publish one trigger job per cron slot of each schedule until signal aborts, then resolve. Each slot enqueues schedule:<name>:<slot ISO time>, so replicas and restarts sharing a queue converge on one job; after startup or a delay, only the latest slot within maxLateMs is published. Invalid options reject, and without onError the first publication failure stops every schedule and rejects.

Complete example and detailed rules.

  • optionsRequired
    RunSchedulesOptions
    Queue, schedules, stop signal and lateness policy.
  • options.queueRequired
    TaskQueue
    Queue receiving one trigger job per slot; share it between scheduler replicas so they converge on the same job.
  • options.schedulesRequired
    readonly TriggerSchedule[]
    At least one schedule, each with a unique name.
  • options.signalRequired
    AbortSignal
    Stops every schedule; runSchedules() then resolves.
  • options.maxLateMsOptional
    number | undefined
    Maximum delay after a slot for it to still be published, including at startup; defaults to 60000. Only the latest slot within this window is published; a negative or non-integer value rejects.
  • options.onErrorOptional
    ((error: unknown, failure: ScheduleFailure) => void) | undefined
    Receives each publication failure with its schedule and slot, and scheduling continues; without it the first failure stops every schedule and rejects runSchedules(). Errors thrown by the callback are ignored.

Promise<void>

export declare function runSchedules(
  options: RunSchedulesOptions,
): Promise<void>;