Add cloudflare-workflows preset for durable execution
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 11.2k
- Forks
- 899
- Avg merge
- 2d 24m
- Merged PRs (30d)
- 40
Description
Describe the feature
Problem
I need to use Cloudflare Workflows with Nitro, but there's no way to export the required WorkflowEntrypoint class from the worker entry point.
Proposed Solution
The cloudflare-durable preset already does this exact pattern for Durable Objects. A cloudflare-workflows preset would be the same thing:
const cloudflareWorkflows = defineNitroPreset(
{
extends: "cloudflare-module",
entry: "./cloudflare/runtime/cloudflare-workflows",
},
{ name: "cloudflare-workflows" as const }
);
The types already anticipate this—exports mentions WorkflowEntrypoint as a use case.
Use Case
Nitro Tasks are fire-and-forget. Workflows solve a different problem: multi-step pipelines that survive failures.
I'm processing large CSV uploads where each step is memoized—if the worker crashes, it picks up where it left off. The workflow can even pause and wait for user input for days. Can't do this with Tasks.
export class CsvProcessingWorkflow extends WorkflowEntrypoint {
async run(event: WorkflowEvent<{ uploadKey: string }>, step: WorkflowStep) {
const csv = await step.do("download", () => this.env.R2.get(event.payload.uploadKey));
const result = await step.do("validate", () => validate(csv));
if (result.hasErrors) {
const decision = await step.waitForEvent("user-decision", { timeout: "7 days" });
if (decision.payload.abort) return { status: "aborted" };
}
await step.do("process", () => process(csv));
return { status: "complete" };
}
}
References
- Cloudflare Workflows docs
- cloudflare-durable.ts - the pattern to follow
- #1974 - Tasks API discussion where durable execution keeps coming up
Additional information
- Would you be willing to help implement this feature?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading src/presets/cloudflare/runtime/cloudflare-durable.ts and compare its preset definition with the proposed cloudflare-workflows entry point. Add the analogous preset using cloudflare/runtime/cloudflare-workflows, then verify that the preset is available and the worker entry point exports WorkflowEntrypoint.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- cloud
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 50/100