Skip to content
API reference

API reference

Kind Export Description
type alias Cadence One cron cadence in one IANA time zone.
type alias ScheduleState Whether a schedule can fire, is paused, or has settled.
type alias ScheduleCore The fields every schedule has; hosts add their own target fields.
type alias Refusal A refused occurrence: the schedule’s new state and when to retry it.
type alias RetryPolicy Initial and maximum delays for exponential retries.
type alias BackoffDelay Pure retry-delay port shared by schedule and delivery owners.
type alias CadenceError Why the next occurrence could not be computed.
constant backoffDelay Bounded exponential delay shared by schedule and delivery owners.
constant defaultRetryPolicy Default backoff: 30 s doubling to at most an hour.
function nextOccurrence() The first occurrence strictly after after. Hosts pass the current time after a firing, so occurrences missed while down or paused coalesce into the next one: a schedule never replays a backlog.
function occurrenceKey() The idempotency key of the schedule’s current occurrence. A retried or re-fired admission of the same occurrence carries the same key, so the host’s action runs at most once per occurrence.
function isDue() Whether the host should fire now; a paused or settled schedule never does.
function settled() Whether a schedule is cancelled or finished.
function afterAdmitted() The occurrence was admitted. A one-shot finishes; a recurring schedule moves to its next occurrence after now, or pauses with the reason if its cadence has none.
function afterRefused() The occurrence was refused. The schedule records why and retries the same occurrence (same key) after a bounded backoff; one failing schedule never delays another.
function paused() Pause admission while preserving the occurrence and any failure reason.
function resumed() Resume is the human retry: it clears the failure and skips recurring occurrences missed while paused.
function cancelled() Cancel an unsettled schedule, leaving an already settled record unchanged.
Signature
type Cadence = Readonly<{
expression: string;
timeZone: string;
}>;

One cron cadence in one IANA time zone.


ScheduleStatetype alias

Section titled “ScheduleState”
Signature
type ScheduleState = "active" | "paused" | "cancelled" | "finished";

Whether a schedule can fire, is paused, or has settled.


ScheduleCoretype alias

Section titled “ScheduleCore”
Signature
type ScheduleCore = Readonly<{
id: string;
cron: Cadence | null;
nextDueAt: number;
state: ScheduleState;
lastError: string | null;
attempt: number;
}>;

The fields every schedule has; hosts add their own target fields.


Signature
type Refusal<S> = Readonly<{
schedule: S;
retryAt: number;
}>;

A refused occurrence: the schedule’s new state and when to retry it.

Type Parameter
S extends ScheduleCore

RetryPolicytype alias

Section titled “RetryPolicy”
Signature
type RetryPolicy = Readonly<{
baseMs: number;
maxMs: number;
}>;

Initial and maximum delays for exponential retries.


BackoffDelaytype alias

Section titled “BackoffDelay”
Signature
type BackoffDelay = (attempt, policy) => number;

Pure retry-delay port shared by schedule and delivery owners.

Attempt one uses baseMs, capped by maxMs; zero and negative attempts retain that same first-delay convention. Later attempts double up to the cap. The owner supplies its policy; this port reads no clock or durable state.

Parameter Type
attempt number
policy RetryPolicy

number


CadenceErrortype alias

Section titled “CadenceError”
Signature
type CadenceError = Readonly<{
kind: "invalid" | "exhausted";
message: string;
}>;

Why the next occurrence could not be computed.

backoffDelayconstant

Section titled “backoffDelay”
Signature
const backoffDelay: BackoffDelay;

Bounded exponential delay shared by schedule and delivery owners.


defaultRetryPolicyconstant

Section titled “defaultRetryPolicy”
Signature
const defaultRetryPolicy: RetryPolicy;

Default backoff: 30 s doubling to at most an hour.

nextOccurrence()function

Section titled “nextOccurrence()”
Signature
function nextOccurrence(
cadence,
after,
): Result<
number,
Readonly<{
kind: "invalid" | "exhausted";
message: string;
}>
>;

The first occurrence strictly after after. Hosts pass the current time after a firing, so occurrences missed while down or paused coalesce into the next one: a schedule never replays a backlog.

Parameter Type
cadence Cadence
after number

Result<number, Readonly<{ kind: "invalid" | "exhausted"; message: string; }>>


occurrenceKey()function

Section titled “occurrenceKey()”
Signature
function occurrenceKey(schedule): string;

The idempotency key of the schedule’s current occurrence. A retried or re-fired admission of the same occurrence carries the same key, so the host’s action runs at most once per occurrence.

Parameter Type
schedule ScheduleCore

string


Signature
function isDue(schedule, now): boolean;

Whether the host should fire now; a paused or settled schedule never does.

Parameter Type
schedule ScheduleCore
now number

boolean


Signature
function settled(schedule): boolean;

Whether a schedule is cancelled or finished.

Parameter Type
schedule ScheduleCore

boolean


afterAdmitted()function

Section titled “afterAdmitted()”
Signature
function afterAdmitted<S>(schedule, now): S;

The occurrence was admitted. A one-shot finishes; a recurring schedule moves to its next occurrence after now, or pauses with the reason if its cadence has none.

Type Parameter
S extends Readonly<{ id: string; cron: | Readonly<{ expression: string; timeZone: string; }> | null; nextDueAt: number; state: ScheduleState; lastError: string | null; attempt: number; }>
Parameter Type
schedule S
now number

S


afterRefused()function

Section titled “afterRefused()”
Signature
function afterRefused<S>(schedule, now, reason, policy?): Refusal<S>;

The occurrence was refused. The schedule records why and retries the same occurrence (same key) after a bounded backoff; one failing schedule never delays another.

Type Parameter
S extends Readonly<{ id: string; cron: | Readonly<{ expression: string; timeZone: string; }> | null; nextDueAt: number; state: ScheduleState; lastError: string | null; attempt: number; }>
Parameter Type Default value
schedule S undefined
now number undefined
reason string undefined
policy RetryPolicy defaultRetryPolicy

Refusal<S>


Signature
function paused<S>(schedule): S;

Pause admission while preserving the occurrence and any failure reason.

Type Parameter
S extends Readonly<{ id: string; cron: | Readonly<{ expression: string; timeZone: string; }> | null; nextDueAt: number; state: ScheduleState; lastError: string | null; attempt: number; }>
Parameter Type
schedule S

S


Signature
function resumed<S>(
schedule,
now,
): Result<
S,
Readonly<{
kind: "invalid" | "exhausted";
message: string;
}>
>;

Resume is the human retry: it clears the failure and skips recurring occurrences missed while paused.

Type Parameter
S extends Readonly<{ id: string; cron: | Readonly<{ expression: string; timeZone: string; }> | null; nextDueAt: number; state: ScheduleState; lastError: string | null; attempt: number; }>
Parameter Type
schedule S
now number

Result<S, Readonly<{ kind: "invalid" | "exhausted"; message: string; }>>


Signature
function cancelled<S>(schedule): S;

Cancel an unsettled schedule, leaving an already settled record unchanged.

Type Parameter
S extends Readonly<{ id: string; cron: | Readonly<{ expression: string; timeZone: string; }> | null; nextDueAt: number; state: ScheduleState; lastError: string | null; attempt: number; }>
Parameter Type
schedule S

S