Stream Workflow instance events via .subscribe()
Workflow instances now support event streaming through WorkflowInstance.subscribe() and the GET /subscribe API endpoint, allowing Workers and HTTP clients to react to workflow events like attempts, sleeps, waits, and rollbacks without polling. Subscriptions stream the complete event history first, then wait for new events in real-time, with optional filtering by event type or cursor position.
You can now stream Workflow instance events via WorkflowInstance.subscribe() and the GET /subscribe API endpoint. Workers and HTTP clients can react to workflow and step events, including attempts, sleeps, waits, and rollbacks, without polling for instance status.
A subscription first streams the entire event history of the Workflow instance. After streaming past events, the subscription waits for new events as the instance runs. You can use filter to receive only specific event types or cursor to start a subscription at a specific event.
Use .subscribe() to update Workflow status in user-facing dashboards, send notifications when steps complete, or trigger follow-up work for specific events.
const instance = await env.MY_WORKFLOW.get("report-123");
using subscription = await instance.subscribe();
while (true) {
const { value, done } = await subscription.next();
if (done) {
break;
}
console.log(value.type, value);
}const instance = await env.MY_WORKFLOW.get("report-123");
using subscription = await instance.subscribe();
while (true) {
const { value, done } = await subscription.next();
if (done) {
break;
}
console.log(value.type, value);
}
For event types, available fields, and subscription options, refer to Subscribe to events.
Source: original entry ↗