API reference
Exports
Section titled “Exports”| 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. |
Cadencetype alias
Section titled “Cadence”type Cadence = Readonly<{ expression: string; timeZone: string;}>;One cron cadence in one IANA time zone.
ScheduleStatetype alias
Section titled “ScheduleState”type ScheduleState = "active" | "paused" | "cancelled" | "finished";Whether a schedule can fire, is paused, or has settled.
ScheduleCoretype alias
Section titled “ScheduleCore”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.
Refusaltype alias
Section titled “Refusal”type Refusal<S> = Readonly<{ schedule: S; retryAt: number;}>;A refused occurrence: the schedule’s new state and when to retry it.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
S extends ScheduleCore |
RetryPolicytype alias
Section titled “RetryPolicy”type RetryPolicy = Readonly<{ baseMs: number; maxMs: number;}>;Initial and maximum delays for exponential retries.
BackoffDelaytype alias
Section titled “BackoffDelay”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
attempt |
number |
policy |
RetryPolicy |
Returns
Section titled “Returns”number
CadenceErrortype alias
Section titled “CadenceError”type CadenceError = Readonly<{ kind: "invalid" | "exhausted"; message: string;}>;Why the next occurrence could not be computed.
backoffDelayconstant
Section titled “backoffDelay”const backoffDelay: BackoffDelay;Bounded exponential delay shared by schedule and delivery owners.
defaultRetryPolicyconstant
Section titled “defaultRetryPolicy”const defaultRetryPolicy: RetryPolicy;Default backoff: 30 s doubling to at most an hour.
nextOccurrence()function
Section titled “nextOccurrence()”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
cadence |
Cadence |
after |
number |
Returns
Section titled “Returns”Result<number, Readonly<{ kind: "invalid" | "exhausted";
message: string; }>>
occurrenceKey()function
Section titled “occurrenceKey()”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
schedule |
ScheduleCore |
Returns
Section titled “Returns”string
isDue()function
Section titled “isDue()”function isDue(schedule, now): boolean;Whether the host should fire now; a paused or settled schedule never does.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
schedule |
ScheduleCore |
now |
number |
Returns
Section titled “Returns”boolean
settled()function
Section titled “settled()”function settled(schedule): boolean;Whether a schedule is cancelled or finished.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
schedule |
ScheduleCore |
Returns
Section titled “Returns”boolean
afterAdmitted()function
Section titled “afterAdmitted()”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 Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
S extends Readonly<{ id: string; cron: | Readonly<{ expression: string; timeZone: string; }> | null; nextDueAt: number; state: ScheduleState; lastError: string | null; attempt: number; }> |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
schedule |
S |
now |
number |
Returns
Section titled “Returns”S
afterRefused()function
Section titled “afterRefused()”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 Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
S extends Readonly<{ id: string; cron: | Readonly<{ expression: string; timeZone: string; }> | null; nextDueAt: number; state: ScheduleState; lastError: string | null; attempt: number; }> |
Parameters
Section titled “Parameters”| Parameter | Type | Default value |
|---|---|---|
schedule |
S |
undefined |
now |
number |
undefined |
reason |
string |
undefined |
policy |
RetryPolicy |
defaultRetryPolicy |
Returns
Section titled “Returns”Refusal<S>
paused()function
Section titled “paused()”function paused<S>(schedule): S;Pause admission while preserving the occurrence and any failure reason.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
S extends Readonly<{ id: string; cron: | Readonly<{ expression: string; timeZone: string; }> | null; nextDueAt: number; state: ScheduleState; lastError: string | null; attempt: number; }> |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
schedule |
S |
Returns
Section titled “Returns”S
resumed()function
Section titled “resumed()”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 Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
S extends Readonly<{ id: string; cron: | Readonly<{ expression: string; timeZone: string; }> | null; nextDueAt: number; state: ScheduleState; lastError: string | null; attempt: number; }> |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
schedule |
S |
now |
number |
Returns
Section titled “Returns”Result<S, Readonly<{ kind: "invalid" | "exhausted"; message:
string; }>>
cancelled()function
Section titled “cancelled()”function cancelled<S>(schedule): S;Cancel an unsettled schedule, leaving an already settled record unchanged.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
S extends Readonly<{ id: string; cron: | Readonly<{ expression: string; timeZone: string; }> | null; nextDueAt: number; state: ScheduleState; lastError: string | null; attempt: number; }> |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
schedule |
S |
Returns
Section titled “Returns”S