Skip to content

Workflows

Workflows are replayable multi-step applications. Execution authority is local SQLite on the node running ocd.

For example, you can use Workflows for:

  • Multi-step applications with durable steps
  • Sleep and wait for events
  • Replay after interruption
ts
export class MyWorkflow extends WorkflowEntrypoint<Env, { hello: string }> {
  async run(event: WorkflowEvent<{ hello: string }>, step: WorkflowStep) {
    const first = await step.do("first", async () => {
      return { ok: true, hello: event.payload.hello };
    });
    return first;
  }
}

export default {
  async fetch(_request: Request, env: Env): Promise<Response> {
    const instance = await env.FLOW.create({ params: { hello: "world" } });
    return Response.json({ id: instance.id, status: await instance.status() });
  },
} satisfies ExportedHandler<{ FLOW: Workflow }>;

Bind in open-compute.json. Workflow bindings require className:

json
{
  "name": "flow-app",
  "main": "src/index.ts",
  "bindings": {
    "FLOW": { "type": "workflow", "id": "<workflow-id>", "className": "MyWorkflow" }
  }
}

Optional schedules is a string array. Grammar: bindings. The CLI is oc / oc run / oc types.

Compatibility

TopicCloudflareopen-compute
Binding / instance APICloudflare WorkflowsSame: create / get / createBatch / deleteBatch, step.do / sleep / event, status / pause / resume / terminate / restart
ExecutionCross-regionLocal SQLite on the node running ocd
CallbacksAt-least-once until result commit; replay skips durable-complete callbacks
External side effectsDo not roll back with Workflow snapshots
Dashboard / observabilityAvailableNot provided
Bindingwrangler{ type, id, className }; className required

Next