Setting the file. One moment.
Chapter 04 · Cloudflare Deploy
Subchapter 4.295
references/workflows/README.mdMarkdown2 KBView on GitHub
Durable multi-step applications with automatic retries, state persistence, and long-running execution.
Available: Free & Paid Workers plans
Workflow: Class extending WorkflowEntrypoint with run method
Instance: Single execution with unique ID & independent state
Steps: Independently retriable units via step.do() - API calls, DB queries, AI invocations
State: Persisted from step returns; step name = cache key
import { WorkflowEntrypoint, WorkflowStep, WorkflowEvent } from 'cloudflare:workers';
type Env = { MY_WORKFLOW: Workflow; DB: D1Database };
type Params = { userId: string };
export class MyWorkflow extends WorkflowEntrypoint<Env, Params> {
async run(event: WorkflowEvent<Params>, step: WorkflowStep) {
const user = await step.do('fetch user', async () => {
return await this.env.DB.prepare('SELECT * FROM users WHERE id = ?')
.bind(event.params.userId).first();
});
await step.sleep('wait 7 days', '7 days');
await step.do('send reminder', async () => {
await sendEmail(user.email, 'Reminder!');
});
}
}waitForEvent() for webhooks/approvals (timeout: 1h → 365d)sleep() / sleepUntil() for scheduling (max 365d)Promise.all() for concurrent stepsGetting Started: configuration.md → api.md → patterns.md
Troubleshooting: gotchas.md