Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Comprehensive Cloudflare platform skill covering Workers, D1, R2, KV, AI, Durable Objects, and security.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/workflows/README.md
1# Cloudflare Workflows23Durable multi-step applications with automatic retries, state persistence, and long-running execution.45## What It Does67- Chain steps with automatic retry logic8- Persist state between steps (minutes → weeks)9- Handle failures without losing progress10- Wait for external events/approvals11- Sleep without consuming resources1213**Available:** Free & Paid Workers plans1415## Core Concepts1617**Workflow**: Class extending `WorkflowEntrypoint` with `run` method18**Instance**: Single execution with unique ID & independent state19**Steps**: Independently retriable units via `step.do()` - API calls, DB queries, AI invocations20**State**: Persisted from step returns; step name = cache key2122## Quick Start2324```typescript25import { WorkflowEntrypoint, WorkflowStep, WorkflowEvent } from 'cloudflare:workers';2627type Env = { MY_WORKFLOW: Workflow; DB: D1Database };28type Params = { userId: string };2930export class MyWorkflow extends WorkflowEntrypoint<Env, Params> {31async run(event: WorkflowEvent<Params>, step: WorkflowStep) {32const user = await step.do('fetch user', async () => {33return await this.env.DB.prepare('SELECT * FROM users WHERE id = ?')34.bind(event.payload.userId).first();35});3637await step.sleep('wait 7 days', '7 days');3839await step.do('send reminder', async () => {40await sendEmail(user.email, 'Reminder!');41});42}43}44```4546## Key Features4748- **Durability**: Failed steps don't re-run successful ones49- **Retries**: Configurable backoff (constant/linear/exponential)50- **Events**: `waitForEvent()` for webhooks/approvals (configurable timeout)51- **Sleep**: `sleep()` / `sleepUntil()` for scheduling52- **Parallel**: `Promise.all()` for concurrent steps53- **Idempotency**: Check-then-execute patterns5455## Retrieval5657These 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:5859- **Limits:** https://developers.cloudflare.com/workflows/reference/limits/60- **Pricing:** https://developers.cloudflare.com/workflows/reference/pricing/61- **Workers API:** https://developers.cloudflare.com/workflows/build/workers-api/6263## Reading Order6465**Getting Started:** configuration.md → api.md → patterns.md66**Troubleshooting:** gotchas.md6768## In This Reference69- [configuration.md](./configuration.md) - wrangler.jsonc setup, step config, bindings70- [api.md](./api.md) - Step APIs, instance management, sleep/parameters71- [patterns.md](./patterns.md) - Common workflows, testing, orchestration72- [gotchas.md](./gotchas.md) - Timeouts, limits, debugging strategies7374## See Also75- [durable-objects](../durable-objects/) - Alternative stateful approach76- [queues](../queues/) - Message-driven workflows77- [workers](../workers/) - Entry point for workflow instances78