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
eventis the triggering event;event.datahas the type you passed todefineWorkflow.eventsis set only for a batched workflow - the coalesced events, witheventbeing the first.attemptstarts at 1 and increases on each retry.runneris the pinned runner id, or""when the run is anycast.erroris set only inside anonFailurehandler - the terminal error that failed the run.logrecords 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)- runfnonce 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 (aDate, ISO string, or epoch ms).waitForEvent(id, { event, timeout })- suspend until a matching event arrives, returning its data, ornulliftimeoutelapses first.runWorkflow(id, { name, app?, runner?, data? })- invoke another workflow as a child and wait for its result. Omitappto resolve the name in the caller's app first, then any app in the namespace; setrunnerto pin the child to a specific runner.emit(id, { name, app?, data? })- emit an event from inside a run. Omitappto broadcast namespace-wide, or set it to narrow the event to one app's triggers.
hashStepId
hashStepId(stepId: string): stringReturns 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.