feat(cloudflare): expand workflows api#611
Conversation
263413f to
a5ca86d
Compare
| * const result = yield* Cloudflare.task({ | ||
| * name: "call-api", |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Done — reshaped to id-first so the name leads and the Effect stays positional, with retries/timeout/rollback in an optional third config object:
yield* Cloudflare.task("process-order", Effect.succeed({ orderId: "abc" }));
yield* Cloudflare.task("call-api", effect, {
retries: { limit: 3, delay: "5 seconds", backoff: "linear" },
rollback: ({ output }) => output ? cleanup(output.id) : Effect.void,
});This keeps the simple task(name, effect) call working unchanged.
| * const event = yield* Cloudflare.waitForEvent<{ approved: boolean }>( | ||
| * "approval", | ||
| * { type: "approval", timeout: "1 day" }, | ||
| * ); |
There was a problem hiding this comment.
Should we support an Effect schema here?
There was a problem hiding this comment.
Deferring this for now to keep the PR focused — waitForEvent (and task/create) stay on the unchecked <T> generic in this change. Adding optional Effect Schema decoding for event payloads is a good follow-up and can land separately.
| export interface WorkflowWaitForEventOptions { | ||
| type: string; | ||
| timeout?: string | number; | ||
| } |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
Ahh, nvm, I see why you separated it out.
|
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 |
Reshape `task` to `task(name, effect, options?)` per review feedback so the
step name leads and the Effect stays positional; retries/timeout/rollback
move to an optional third config object. Keeps the simple `task(name, effect)`
call working.
Also migrate the workflow examples to the new `create({ params })` API and
fix the WorkflowBridge step-runner R variance surfaced by the main merge.
Co-authored-by: Cursor <cursoragent@cursor.com>
Expand the Effect-native Cloudflare Workflow wrapper to cover the current Workers API surface with an object-based step API.
waitForEventsupportcreateBatch,restart,sendEvent, rollback status, and extended event metadata