Skip to content

feat(cloudflare): expand workflows api#611

Open
Gerbuuun wants to merge 5 commits into
alchemy-run:mainfrom
Gerbuuun:feat/cloudflare-workflow-api-main
Open

feat(cloudflare): expand workflows api#611
Gerbuuun wants to merge 5 commits into
alchemy-run:mainfrom
Gerbuuun:feat/cloudflare-workflow-api-main

Conversation

@Gerbuuun

@Gerbuuun Gerbuuun commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Expand the Effect-native Cloudflare Workflow wrapper to cover the current Workers API surface with an object-based step API.

const result = yield* Cloudflare.task({
  name: "call-api",
  retries: { limit: 3, delay: "5 seconds", backoff: "linear" },
  effect: Effect.gen(function* () {
    const context = yield* Cloudflare.WorkflowStepContext;
    return { attempt: context.attempt };
  }),
  rollback: ({ output }) =>
    output ? cleanup(output.id) : Effect.void,
});
const instance = yield* workflow.create({
  id: "order-abc",
  params: { orderId: "abc" },
});

const approval = yield* Cloudflare.waitForEvent("approval", {
  type: "approval",
  timeout: "1 day",
});

yield* instance.sendEvent({
  type: "approval",
  payload: { approved: true },
});
  • Add step config, step context, rollback, and waitForEvent support
  • Add create options, createBatch, restart, sendEvent, rollback status, and extended event metadata
  • Update Workflow docs generation to pick the resource JSDoc instead of earlier helper class comments

@Gerbuuun Gerbuuun force-pushed the feat/cloudflare-workflow-api-main branch from 263413f to a5ca86d Compare June 13, 2026 12:32
Comment on lines +431 to +432
* const result = yield* Cloudflare.task({
* name: "call-api",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it wouldn't be better if the id was the first argument instead of an object property to align with the rest of alchemy's api design.

Comment on lines +459 to +462
* const event = yield* Cloudflare.waitForEvent<{ approved: boolean }>(
* "approval",
* { type: "approval", timeout: "1 day" },
* );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we support an Effect schema here?

Comment on lines +100 to +103
export interface WorkflowWaitForEventOptions {
type: string;
timeout?: string | number;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These could just be defined inline. It's how they do it.

    export abstract class WorkflowStep {
        do<T extends Rpc.Serializable<T>>(name: string, callback: (ctx: WorkflowStepContext) => Promise<T>, rollbackOptions?: WorkflowStepRollbackOptions<T>): Promise<T>;
        do<T extends Rpc.Serializable<T>>(name: string, config: WorkflowStepConfig, callback: (ctx: WorkflowStepContext) => Promise<T>, rollbackOptions?: WorkflowStepRollbackOptions<T>): Promise<T>;
        sleep: (name: string, duration: WorkflowSleepDuration) => Promise<void>;
        sleepUntil: (name: string, timestamp: Date | number) => Promise<void>;
        waitForEvent<T extends Rpc.Serializable<T>>(name: string, options: {
            type: string;
            timeout?: WorkflowTimeoutDuration | number;
        }): Promise<WorkflowStepEvent<T>>;
    }

I do need this though, so thank you for putting up the PR!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, nvm, I see why you separated it out.

@Gerbuuun

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback. I'm in the middle of exam week so it'll be probably end of next week I'll continue working on this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants