The event payload instances of this Workflow are started with.
Constructs a WorkflowBinding instance.
The event payload instances of this Workflow are started with.
Optionalsettings: WorkflowSettings
Resolved settings. Defaults to resolve('workflow'), so callers
normally construct this with no arguments at all.
The binding name this instance resolves.
The binding name as declared in wrangler.json.
Starts an instance.
A handle to the new instance.
Returns as soon as the instance is accepted, not when it finishes — a Workflow that runs for an hour returns a handle in milliseconds. Read the outcome later with status.
Supplying an id in options makes the start idempotent in the only sense
Cloudflare offers: a second start under an id that already exists throws
rather than producing a second run.
MissingBindingError When the Workflow binding is absent.
Starts several instances in one call.
Handles to the new instances, in the order they were given.
Cloudflare caps a batch at 100 instances, or at 1 MiB of payload, whichever is reached first — so a caller fanning out over a large universe splits the work itself rather than relying on this to do it. Nothing here chunks on the caller's behalf, because the right chunk size depends on how big the payloads are and only the caller knows that.
MissingBindingError When the Workflow binding is absent.
Reads back an instance started earlier.
The Worker environment.
The instance id.
A handle to the instance, which can be paused, resumed, terminated or read.
MissingBindingError When the Workflow binding is absent.
Checks whether the binding is available on the given environment.
Use this to degrade gracefully when a binding is optional.
The Worker environment.
true when the binding is present.
Resolves the binding, failing fast when it is not configured.
The Worker environment.
The resolved binding.
MissingBindingError When the binding is absent from the environment.
Reads an instance's current status.
The Worker environment.
The instance id.
The instance's status, plus its output or error when it has one.
The one method here without a counterpart on the binding, and the only one worth adding: reporting a run's progress is what a status endpoint does on every request, and it would otherwise take two awaits every time.
A finished instance carries its result in output; a failed one carries
error. Both disappear once retention lapses — see WorkflowSettings.
MissingBindingError When the Workflow binding is absent.
Privatewith
Accessor for a Workflows binding.
Remarks
A Workflow is durable execution: a class of steps that survives restarts, retries a failed step without replaying the ones before it, and can sleep for a month between two of them. This accessor is the producer side — starting instances and reading them back. The steps themselves live in a
WorkflowEntrypointclass the Worker exports, which this package neither provides nor wraps: a base class that must be exported from the Worker's own entry, and named in its ownwrangler.json, has nothing an adapter can add.The method names mirror the platform's —
create,createBatch,get— because an accessor that renames operations makes Cloudflare's documentation stop matching this one.statusis the single addition, saving the two-step that reading an instance's state otherwise takes.Why there is no
WorkflowServiceEvery binding here but this one and Browser Rendering has a capability service beside it, and the reason differs from Browser's. There the obstacle was a dependency; here it is that the kernel has no capability to implement.
@bayudwiyansatria/corenames aCacheStore, aDataStore, aMessageQueue— abstractions with more than one plausible provider. Durable execution has none yet, and inventing one to sit in front of a single implementation with no consumers would be ceremony rather than abstraction, which the binding guide says in as many words.That leaves nothing lost, because unlike Browser Rendering the binding's own operations cost no dependency:
Workflow,WorkflowInstanceand their options come from@cloudflare/workers-types, already a peer. A consumer gets the real surface here rather than a bare handle.Example
Author
Bayu Dwiyan Satria
Version
1.0.0
Since
1.3.0