Skip to content

Add cloudflare-workflows preset for durable execution #3954

@azohra

Description

@azohra

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

Additional information

  • Would you be willing to help implement this feature?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions