Workflows step.do() levels up: richer step context and ReadableStream support!
Hey there, it's me, Shiichan! Today I've got a nice little update: Workflows just made step.do() a bit more convenient.
What was announced?
Over on the Cloudflare Changelog, Workflows added two features to step.do(). One is more context information you can read inside the step callback, and the other is that a step can now return a ReadableStream.
The story so far
Up to now, the step.do() callback already let you read attempt (which retry you're on), but you couldn't see the step's name, how many times it had run, or what its config actually was. On top of that, a step's return value had a size limit, which made handling large data a little awkward.
What changes
From now on, a step can clearly know "what kind of step am I?" That makes it easy to tell which iteration you're on when you run the same step in a loop, and to check the timeout and retry settings that are really in effect. And since you can return large outputs as a stream, the range of data you can handle grows a lot.
Dive Deep
Here are the three newly added context properties.
step.name: the step name you passed tostep.do()step.count: how many times a step with that name has been invoked in this instance (1-indexed). Handy in loopsconfig: the resolved step configuration fortimeoutandretries, with defaults applied
As for ReadableStream, a step can now return a stream directly. Regular step outputs are limited to 1 MiB, but streamed outputs can carry much larger payloads. For example, you might grab a large file from R2 and return its body as-is.
const largePayload = await step.do("fetch-large-file", async () => {
const object = await env.MY_BUCKET.get("large-file.bin");
return object.body;
});
One thing to keep in mind: streamed outputs still count toward your Workflow instance storage limit, so don't forget that.
Wrap-up
- Cloudflare's Workflows
step.do()gained additional step context andReadableStreamsupport - The context now includes
step.name,step.count, andconfig, making loops and config checks easier - Returning a
ReadableStreamfrom a step lets you handle outputs bigger than 1 MiB (but they still count toward the storage limit)
This update is for folks building complex multi-step processes on Workflows, or anyone who needs to move large data between steps!