Steps

The handler context and the durable step API - run, sleep, sleepUntil, waitForEvent, runWorkflow, emit.

The handler context

Every handler receives a StepContext. It carries the triggering event, the durable step API, and metadata about the run.

Prop

Type

  • event is the triggering event; event.data has the type you passed to defineWorkflow.
  • events is set only for a batched workflow - the coalesced events, with event being the first.
  • attempt starts at 1 and increases on each retry. runner is the pinned runner id, or "" when the run is anycast.
  • error is set only inside an onFailure handler - the terminal error that failed the run.
  • log records structured, replay-safe logs from workflow code - see Logging.

step

The step API makes each unit of work durable. Every step takes a stable id that is unique within the workflow: its result is recorded under that id and, on replay after a crash or retry, a completed step returns its saved result instead of running again.

Prop

Type

  • run(id, fn) - run fn once and memoize its result. The unit of durable work.
  • sleep(id, duration) - pause for a relative duration (a string like "30s"/"1h" or a number of milliseconds). The run is suspended, not blocked, and survives restarts.
  • sleepUntil(id, at) - pause until an absolute time (a Date, ISO string, or epoch ms).
  • waitForEvent(id, { event, timeout }) - suspend until a matching event arrives, returning its data, or null if timeout elapses first.
  • runWorkflow(id, { name, app?, runner?, data? }) - invoke another workflow as a child and wait for its result. Omit app to resolve the name in the caller's app first, then any app in the namespace; set runner to pin the child to a specific runner.
  • emit(id, { name, app?, data? }) - emit an event from inside a run. Omit app to broadcast namespace-wide, or set it to narrow the event to one app's triggers.

hashStepId

hashStepId(stepId: string): string

Returns the stable hash the engine uses to key a step's memoized result. Exposed for tooling that needs to correlate a step id with its recorded entry; you rarely call it directly.

On this page