Workflows Pipeline Demo
Durable fetch → AI summarize → R2 pipeline using Cloudflare Workflows with step.do and step.sleep
A durable three-step pipeline built with Cloudflare Workflows: fetch a URL, pause with step.sleep(), summarize the page with Workers AI, and store the JSON result in R2. Poll status by workflow instance ID.
Features
- POST /run - Start a workflow instance from a URL
- GET /status/:instanceId - Poll status and final output
- Three durable steps - fetch, summarize, store (each wrapped in
step.do()) - Pause demo -
step.sleep("3 seconds")between fetch and summarize
API Reference
POST /run
Start a new workflow instance.
Prop
Type
Example Request
curl -X POST "https://your-worker.workers.dev/run" \
-H "Content-Type: application/json" \
-d '{"url":"https://example.com"}'Success Response (202)
{
"instanceId": "abc-123",
"status": "running"
}Error Codes
400- Invalid JSON (INVALID_BODY) or URL (INVALID_URL)502- Workflow start failed (WORKFLOW_ERROR)
GET /status/:instanceId
Poll workflow status and result.
Example Request
curl "https://your-worker.workers.dev/status/abc-123"Success Response
{
"instanceId": "abc-123",
"status": "complete",
"output": {
"url": "https://example.com/",
"summary": "Example Domain is a placeholder site for documentation examples.",
"r2Key": "summaries/abc-123.json"
},
"error": null
}Error Codes
400- Missing instance id (INVALID_INSTANCE_ID)404- Instance not found (NOT_FOUND)
Use Cases
- Learn
WorkflowEntrypoint,step.do(), andstep.sleep()patterns - Build durable multi-step pipelines that survive retries and pauses
- Combine Workflows with Workers AI and R2 in one reference worker
Limitations
- Demo HTML extraction is basic (title + stripped tags); not suitable for complex SPAs
- Requires R2 bucket, Workers AI, and Workflows enabled on your account
- Workflow sleep adds latency by design for the demo
Deployment
Configure bindings
Create R2 bucket workflows-pipeline-summaries and enable Workers AI. The workflow binding is declared in wrangler.json.
Test your deployment
curl -X POST "https://your-worker.workers.dev/run" \
-H "Content-Type: application/json" \
-d '{"url":"https://example.com"}'Local Development
cd apps/experiments/workflows-pipeline-demo
npm install
npm run devConfiguration
| Binding | Purpose |
|---|---|
PIPELINE | Cloudflare Workflow (SummaryPipeline class) |
AI | Workers AI summarization |
SUMMARIES | R2 bucket for stored JSON summaries |
Cloudflare Features Used
- Workers - Edge compute runtime
- Workflows - Durable multi-step execution
- Workers AI - LLM summarization
- R2 - Object storage for pipeline output