Skip to content
brought to you byVoidZero

Workflows ​

Import the Workflow helpers from void/workflows in server code. The Workflows guide shows how to schedule a post and start an instance from a route.

defineWorkflow(definition) ​

Default-export the definition from a file in workflows/. Only run is required:

  • run(event, step, { env, ctx }) receives the instance event, Cloudflare's WorkflowStep, your app's typed Worker bindings, and its execution context. The value you return is available as output on the completed instance's status.
  • params accepts a Standard Schema. Callers send its input type. Void validates the payload when the instance starts and passes the schema's output to run as event.payload. Validation also applies to instances started through Cloudflare.
  • name pins the resource identity when you rename or move the file. Run void info to see which name to use.

With no schema, annotate the event as WorkflowEvent<MyParams> or supply the type as defineWorkflow<MyParams>(). The default environment type is CloudBindings, just like c.env in a route. You can supply your own environment type with defineWorkflow<MyParams, MyEnv>().

Cloudflare delivers an empty object when a caller omits params. If a schema should supply defaults in that case, make it accept {}. The handler receives exactly what the schema returns, including undefined.

defineWorkflowEntrypoint(definition) ​

Use defineWorkflowEntrypoint({ class: MyWorkflow }) to register a native Cloudflare WorkflowEntrypoint class. You can also pass a name to pin its identity. Void infers the payload type from the class's run(event, step) method. Callers can omit params when that type accepts an empty object.

WorkflowApi ​

Use the default export to start instances or get an existing one:

MemberWhat you can do
create(options?)Start one instance. Pass params when the definition requires input. Use id to choose the instance ID.
createBatch({ instances })Start up to 100 instances with individual IDs and options. Each entry accepts the same options as create().
createBatch({ count, params })Start 1–100 instances with generated IDs and shared options. You can also pass retention and locationHint.
get(id)Get an instance to read its status, send it an event, pause, resume, restart, or terminate it.
classAccess the registered entrypoint class.

Both batch forms return { created, errors }. Check errors for entries that could not start; each includes its index, id, code, and message. Use status() on a created instance to check the outcome of its run. See the Cloudflare batch API.

You can pass an explicit binding as the first argument to create(), createBatch(), or get(). After void prepare, TypeScript checks calls such as PublishPost.create(c.env.WORKFLOW_PUBLISH_POST, { params }) against the Workflow's input type.

WorkflowParamsError ​

Void throws WorkflowParamsError at the entrypoint when the schema rejects the incoming payload. Its issues array contains a message and an optional field path for each problem. The instance fails before your run callback executes. Use await instance.status() to inspect the failure.

Types ​

WorkflowEvent, WorkflowStep, WorkflowContext, WorkflowCreateOptions, WorkflowBatchOptions, WorkflowApi, and WorkflowRun are available from void/workflows.