|
|
há 3 dias atrás | |
|---|---|---|
| .. | ||
| README.md | há 3 dias atrás | |
| api.md | há 3 dias atrás | |
| configuration.md | há 3 dias atrás | |
| gotchas.md | há 3 dias atrás | |
| patterns.md | há 3 dias atrás | |
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.payload.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 (configurable timeout)sleep() / sleepUntil() for schedulingPromise.all() for concurrent stepsThese reference files cover API shapes, code patterns, and debugging — things that are stable. For limits, pricing, and other values that change, always fetch the latest from the official docs:
Getting Started: configuration.md → api.md → patterns.md
Troubleshooting: gotchas.md