nitrojs / nitrojs/nitro

Add cloudflare-workflows preset for durable execution

Open
#3,954 3 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement v3
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

Additional information
  • Would you be willing to help implement this feature?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.