Skip to content

Durability API

Creates typed operation methods and one alarm handler. The operation map is inferred from handlers; named scheduler methods are inferred from options.alarms.

type DurableHandler<TPayload, TResult> = (
call: DurableCall<TPayload>
) => TResult | Promise<TResult>;
DurableCall fieldMeaning
idStable caller-provided idempotency key
operationHandler name
payloadJSON-serializable typed input
attemptOne-based attempt number
signalAttempt-scoped timeout signal

For a sendEmail handler:

await durability.sendEmail({ id, payload });
const state = await durability.sendEmail.getResult(id);

Registration resolves after its storage transaction. getResult returns one of:

  • { status: 'not_found' }
  • { status: 'pending', attempt, nextAttemptAt, lastError }
  • { status: 'failed', attempt, error }
  • { status: 'completed', result }
OptionDefaultPurpose
alarmsnoneNamed logical alarm handlers
alarmMethodsnonePer-name timeout, retry, and retryTimeouts overrides
alarmConcurrency10Maximum immediate operations executed concurrently
alarmHandoffMs14 minutesTime before unfinished work is handed to a fresh alarm invocation
attemptTimeoutMs5 minutesMaximum duration of one attempt
methodsnonePer-operation timeout and retry overrides
retries.maxAttempts5Total attempts, including the first
retries.delayjittered exponentialDelay function returning milliseconds
type DurableAlarmHandler = (
info: DurableAlarmInfo
) => unknown | Promise<unknown>;

Schedule a configured name with a Unix timestamp in milliseconds:

await durability.alarm.cleanup(Date.now() + 60_000);

Call durability.alarm(info?) from the Durable Object’s platform alarm callback.

Moves the package schema to a named migration or null for complete rollback.

Exposes the ordered package migration list for inspection. createDurability normally applies it automatically.

Import retry helpers from durability/utils:

import { exponential, jitter } from 'durability/utils';
ErrorMeaning
NonRetryableErrorFail the operation or named alarm without another attempt
DuplicateDurableCallErrorAn ID belongs to a different operation
DurableAttemptTimeoutErrorAn operation exceeded its attempt timeout
DurableAlarmTimeoutErrorA named alarm exceeded its attempt timeout

Persisted terminal errors retain their serialized name and message.