A Workflow is a durable function that runs as a named sequence of steps, sleeps, and events. celld runs each instance as a cell. Read the Cloudflare Workflows documentation for the API.
The Workflow example fetches a document and stores the result of a durable step.
- A class extends
WorkflowEntrypointand implementsrun(event, step).event.payloadholds the parameters, and the return value becomes theoutputfield ofstatus(). step.do(name, callback)runs a durable step, and it retries the callback on failure.step.sleep(name, duration)andstep.sleepUntil(name, timestamp)stop the instance until a deadline.step.waitForEvent(name, options)stops the instance until a matching event.env.MY_WORKFLOW.create(),createBatch(), andget(id)return an instance.deleteBatch()deletes several instances.- An instance has
status(),sendEvent(),pause(),resume(),restart(),terminate(), anddelete().
Each time an instance makes progress, celld calls run() again from the first
line. A finished step returns its stored result and does not run its callback
again. All code outside a step callback therefore runs again on every replay.
Put each subrequest, each side effect, and each value that must stay stable
inside a step.do() callback, as the
rules of Workflows
require. A step whose result did not commit before a node failure runs again,
so a step callback must tolerate a second attempt.
run() can await work that is not a step, but a replay cannot resume that
await. celld fails the instance when such work keeps run() pending for 60
seconds while no step runs or waits.
step.waitForEvent() times out after 24 hours by default. An event that
arrives before the instance reaches its wait step is buffered. A sleep, a wait,
and a pending retry each store their deadline, so a crash or a slow replay
cannot move the deadline. status() reports waiting for all three.
A waiting instance holds no isolate. Its cell hibernates when the next deadline
is further away than the near-alarm residency window. That window is one hour,
and CELLD_ALARM_RESIDENT_MS changes it.
step.do() uses the Cloudflare retry defaults when the call supplies no
retries object: 5 retries, a delay of 10 seconds, exponential backoff, and a
timeout of 10 minutes for one attempt.
celld sets no limit on the number of concurrent instances. Fleet memory and the resident-cell cap bound it.
- celld retains a successful or failed instance for 30 days by default. Each
duration in the
retentionoption can be at most 30 days. locationHintaccepts the Cloudflare values, but fleet ownership selects the cell location.- Non-step work cannot remain pending for more than 60 seconds.
- A step result, an event payload, and the workflow parameters each have a 1 MiB limit.
- Rollback, a sensitive step result, and a
ReadableStreamstep result are unavailable. - A
workflowsentry cannot carryschedules,limits, or ascript_namethat names another script. - The Workflows REST API and the
wrangler workflowscommands are unavailable. Drive an instance through the binding.
The Cloudflare compatibility page lists the runtime APIs and the unsupported services.