cloudflare-workflows
Build durable, long-running workflows on Cloudflare Workers with automatic retries, state persistence, and multi-step orchestration. Supports step.do, step.sleep, step.waitForEvent, and runs for hours to days. Use when: creating long-running workflows, implementing retry logic, building event-driven processes, coordinating API calls, scheduling multi-step tasks, or troubleshooting NonRetryableError, I/O context, serialization errors, or workflow execution failures. Keywords: cloudflare workflows, workflows workers, durable execution, workflow step, WorkflowEntrypoint, step.do, step.sleep, workflow retries, NonRetryableError, workflow state, wrangler workflows, workflow events, long-running tasks, step.sleepUntil, step.waitForEvent, workflow bindings
What this skill does
# Cloudflare Workflows **Status**: Production Ready ✅ **Last Updated**: 2025-10-22 **Dependencies**: cloudflare-worker-base (for Worker setup) **Latest Versions**: [email protected], @cloudflare/[email protected] --- ## Quick Start (10 Minutes) ### 1. Create a Workflow Use the Cloudflare Workflows starter template: ```bash npm create cloudflare@latest my-workflow -- --template cloudflare/workflows-starter --git --deploy false cd my-workflow ``` **What you get:** - WorkflowEntrypoint class template - Worker to trigger workflows - Complete wrangler.jsonc configuration ### 2. Understand the Basic Structure **src/index.ts:** ```typescript import { WorkflowEntrypoint, WorkflowStep, WorkflowEvent } from 'cloudflare:workers'; type Env = { MY_WORKFLOW: Workflow; }; type Params = { userId: string; email: string; }; export class MyWorkflow extends WorkflowEntrypoint<Env, Params> { async run(event: WorkflowEvent<Params>, step: WorkflowStep) { // Access params from event.payload const { userId, email } = event.payload; // Step 1: Do some work const result = await step.do('process user', async () => { return { processed: true, userId }; }); // Step 2: Wait before next action await step.sleep('wait 1 hour', '1 hour'); // Step 3: Continue workflow await step.do('send email', async () => { // Send email logic return { sent: true, email }; }); // Optional: return final state return { completed: true, userId }; } } // Worker to trigger workflow export default { async fetch(req: Request, env: Env): Promise<Response> { // Create new workflow instance const instance = await env.MY_WORKFLOW.create({ params: { userId: '123', email: '[email protected]' } }); return Response.json({ id: instance.id, status: await instance.status() }); } }; ``` ### 3. Configure Wrangler **wrangler.jsonc:** ```jsonc { "name": "my-workflow", "main": "src/index.ts", "compatibility_date": "2025-10-22", "workflows": [ { "name": "my-workflow", "binding": "MY_WORKFLOW", "class_name": "MyWorkflow" } ] } ``` ### 4. Deploy and Test ```bash # Deploy workflow npm run deploy # Trigger workflow (visit in browser or curl) curl https://my-workflow.<subdomain>.workers.dev/ # View workflow instances npx wrangler workflows instances list my-workflow # Check instance status npx wrangler workflows instances describe my-workflow <instance-id> ``` --- ## WorkflowEntrypoint Class ### Extend WorkflowEntrypoint Every Workflow must extend `WorkflowEntrypoint` and implement a `run()` method: ```typescript export class MyWorkflow extends WorkflowEntrypoint<Env, Params> { async run(event: WorkflowEvent<Params>, step: WorkflowStep) { // Workflow steps here } } ``` **Type Parameters:** - `Env` - Environment bindings (KV, D1, R2, etc.) - `Params` - Type of workflow parameters passed via `event.payload` ### run() Method ```typescript async run( event: WorkflowEvent<Params>, step: WorkflowStep ): Promise<T | void> ``` **Parameters:** - `event` - Contains workflow metadata and payload - `step` - Provides step methods (do, sleep, sleepUntil, waitForEvent) **Returns:** - Optional return value (must be serializable) - Return value available via instance.status() **Example:** ```typescript export class OrderWorkflow extends WorkflowEntrypoint<Env, OrderParams> { async run(event: WorkflowEvent<OrderParams>, step: WorkflowStep) { const { orderId, customerId } = event.payload; // Access bindings via this.env const order = await this.env.DB.prepare( 'SELECT * FROM orders WHERE id = ?' ).bind(orderId).first(); const result = await step.do('process payment', async () => { // Payment processing return { paid: true, amount: order.total }; }); // Return final state return { orderId, status: 'completed', paidAmount: result.amount }; } } ``` --- ## Step Methods ### step.do() - Execute Work ```typescript step.do<T>( name: string, config?: WorkflowStepConfig, callback: () => Promise<T> ): Promise<T> ``` **OR** (config is optional): ```typescript step.do<T>( name: string, callback: () => Promise<T> ): Promise<T> ``` **Parameters:** - `name` - Step name (for observability) - `config` (optional) - Retry configuration - `callback` - Async function that does the work **Returns:** - The value returned from callback (must be serializable) **Example:** ```typescript // Simple step const files = await step.do('fetch files', async () => { const response = await fetch('https://api.example.com/files'); return await response.json(); }); // Step with retry config const result = await step.do( 'call payment API', { retries: { limit: 10, delay: '10 seconds', backoff: 'exponential' }, timeout: '5 minutes' }, async () => { const response = await fetch('https://payment-api.example.com/charge', { method: 'POST', body: JSON.stringify({ amount: 100 }) }); return await response.json(); } ); ``` **CRITICAL - Serialization:** - Return value must be JSON serializable - ✅ Allowed: string, number, boolean, Array, Object, null - ❌ Forbidden: Function, Symbol, circular references, undefined - Step will throw error if return value isn't serializable --- ### step.sleep() - Relative Sleep ```typescript step.sleep(name: string, duration: WorkflowDuration): Promise<void> ``` **Parameters:** - `name` - Step name - `duration` - Number (milliseconds) or human-readable string **Accepted units:** - `"second"` / `"seconds"` - `"minute"` / `"minutes"` - `"hour"` / `"hours"` - `"day"` / `"days"` - `"week"` / `"weeks"` - `"month"` / `"months"` - `"year"` / `"years"` **Examples:** ```typescript // Sleep for 5 minutes await step.sleep('wait 5 minutes', '5 minutes'); // Sleep for 1 hour await step.sleep('hourly delay', '1 hour'); // Sleep for 2 days await step.sleep('wait 2 days', '2 days'); // Sleep using milliseconds await step.sleep('wait 30 seconds', 30000); // Common pattern: schedule daily task await step.do('send daily report', async () => { // Send report }); await step.sleep('wait until tomorrow', '1 day'); // Workflow continues next day ``` **Priority:** - Workflows resuming from sleep take priority over new instances - Ensures older workflows complete before new ones start --- ### step.sleepUntil() - Sleep to Specific Date ```typescript step.sleepUntil( name: string, timestamp: Date | number ): Promise<void> ``` **Parameters:** - `name` - Step name - `timestamp` - Date object or UNIX timestamp (milliseconds) **Examples:** ```typescript // Sleep until specific date const launchDate = new Date('2025-12-25T00:00:00Z'); await step.sleepUntil('wait for launch', launchDate); // Sleep until UNIX timestamp const timestamp = Date.parse('24 Oct 2024 13:00:00 UTC'); await step.sleepUntil('wait until time', timestamp); // Sleep until next Monday 9am UTC const nextMonday = new Date(); nextMonday.setDate(nextMonday.getDate() + ((1 + 7 - nextMonday.getDay()) % 7 || 7)); nextMonday.setUTCHours(9, 0, 0, 0); await step.sleepUntil('wait until Monday 9am', nextMonday); // Schedule work at specific time await step.do('prepare campaign', async () => { // Prepare marketing campaign }); const campaignLaunch = new Date('2025-11-01T12:00:00Z'); await step.sleepUntil('wait for campaign launch', campaignLaunch); await step.do('launch campaign', async () => { // Launch campaign }); ``` --- ### step.waitForEvent() - Wait for External Event ```typescript step.waitForEvent<T>( name: string, options: { type: string; timeout?: string | number } ): Promise<T> ``` **Parameters:** - `name` - Step name - `options.type` - Event type to match - `options.timeout` (optional) - Max wait time (default: 24 hours) **Returns:** - The event payload sent via `instance.sendEvent()` **Example:** ```typescript ex
Related in Backend & APIs
jfrog
IncludedInteract with the JFrog Platform via the JFrog CLI and REST/GraphQL APIs. Use this skill when the user wants to manage Artifactory repositories, upload or download artifacts, manage builds, configure permissions, manage users and groups, work with access tokens, configure JFrog CLI servers, search artifacts, manage properties, set up replication, manage JFrog Projects, run security audits or scans, look up CVE details, query exposures scan results from JFrog Advanced Security, manage release bundles and lifecycle operations, aggregate or export platform data, or perform any JFrog Platform administration task. Also use when the user mentions jf, jfrog, artifactory, xray, distribution, evidence, apptrust, onemodel, graphql, workers, mission control, curation, advanced security, exposures, or any JFrog product name.
cupynumeric-migration-readiness
IncludedPre-migration readiness assessor for porting NumPy to cuPyNumeric. Use BEFORE substantial porting work begins when the user asks whether code will scale on GPU, whether they should migrate to cuPyNumeric, which NumPy patterns transfer cleanly, what must be refactored before porting, or mentions pre-port assessment, scaling analysis, or refactor planning. Inspect the user's source code, look up NumPy usage, cross-reference the cuPyNumeric API support manifest, and distinguish distributed-scaling-friendly patterns from blockers such as unsupported APIs, scalar synchronization, host round-trips, Python/object-heavy control flow, shape/data-dependent branching, and in-place mutation hazards. Produce a verdict of READY, LIGHT REFACTOR, SIGNIFICANT REFACTOR, or NOT RECOMMENDED, with concrete refactor pointers.
alibabacloud-data-agent-skill
IncludedInvoke Alibaba Cloud Apsara Data Agent for Analytics via CLI to perform natural language-driven data analysis on enterprise databases. Data Agent for Analytics is an intelligent data analysis agent developed by Alibaba Cloud Database team for enterprise users. It automatically completes requirement analysis, data understanding, analysis insights, and report generation based on natural language descriptions. This tool supports: discovering data resources (instances/databases/tables) managed in DMS, initiating query or deep analysis sessions, real-time progress tracking, and retrieving analysis conclusions and generated reports. Use this Skill when users need to query databases, analyze data trends, generate data reports, ask questions in natural language, or mention "Data Agent", "data analysis", "database query", "SQL analysis", "data insights".
token-optimizer
IncludedReduce OpenClaw token usage and API costs through smart model routing, heartbeat optimization, budget tracking, and native 2026.2.15 features (session pruning, bootstrap size limits, cache TTL alignment). Use when token costs are high, API rate limits are being hit, or hosting multiple agents at scale. The 4 executable scripts (context_optimizer, model_router, heartbeat_optimizer, token_tracker) are local-only — no network requests, no subprocess calls, no system modifications. Reference files (PROVIDERS.md, config-patches.json) document optional multi-provider strategies that require external API keys and network access if you choose to use them. See SECURITY.md for full breakdown.
resend-cli
IncludedUse this skill when the task is specifically about operating Resend from an AI agent, terminal session, or CI job via the official resend CLI: installing/authenticating the CLI, sending/listing/updating/cancelling emails, batch sends, domains and DNS, webhooks and local listeners, inbound receiving, contacts, topics, segments, broadcasts, templates, API keys, profiles, or debugging Resend CLI/API failures. Trigger on mentions of Resend CLI, `resend`, `resend doctor`, `resend emails send`, `resend domains`, `resend webhooks listen`, `resend emails receiving`, or agent-friendly terminal automation.
alibabacloud-odps-maxframe-coding
IncludedUse this skill for MaxFrame SDK development and documentation navigation on Alibaba Cloud MaxCompute (ODPS). Helps answer MaxFrame API, concept, official example, and supported pandas API questions; create data processing programs; read/write MaxCompute tables; debug jobs (remote or local); and build custom DPE runtime images. Trigger when users mention MaxFrame, MaxCompute with MaxFrame, ODPS table processing, DPE runtime, MaxFrame docs/examples, DataFrame/Tensor operations, or GPU runtime setup. Works for both English and Chinese queries about Alibaba Cloud data processing with MaxFrame.