Defining workflows
defineWorkflow - declare a workflow's name, triggers, retry policy, flow control, and handler.
defineWorkflow
Declares a workflow: its name, what triggers it, how it retries and runs under load, and the handler
that does the work. It returns the definition unchanged - it exists for type inference over your event
data. Pass a type parameter to type ctx.event.data:
const orderCreated = defineWorkflow<{ orderId: string }>({
name: "order.created",
retry: { maxAttempts: 3 },
handler: async (ctx) => {
const { orderId } = ctx.event.data; // typed as { orderId: string }
return ctx.step.run("ship", () => ship(orderId));
},
});Prop
Type
triggers decides what starts the workflow - event triggers ({ event, if? }, with an optional
CEL filter) and cron triggers ({ cron }). Omit it and the workflow
is started by an event matching its name. The flow-control fields (concurrency, throttle,
rateLimit, debounce, batch, priority, singleton, idempotency) are documented in the
flow-control reference; onFailure runs once after the run has exhausted its
retries (see retries).
RetryConfig
The shape of the retry field - the per-workflow retry policy each step inherits.
Prop
Type