-
-
Notifications
You must be signed in to change notification settings - Fork 772
Open
Labels
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?