Run workflows through a queue
Start with the producer and worker.
Start with the producer and worker. Use a queued task to wait for remote work, or a workflow job to preserve progress between worker processes.
Wait for a job inside a workflow
Section titled “Wait for a job inside a workflow”defineQueuedTask() is a workflow task that enqueues a job, polls until it settles and validates its value with decode.
The job ID comes from the run’s executionId and the task key, so a resumed durable run waits on the same job. Cancelling the workflow cancels the job. For a job stopped by a usage limit, see Quota pauses.
Run a checkpointed workflow per job
Section titled “Run a checkpointed workflow per job”defineWorkflowJob() turns a handler into one durable run per job. The job input is { runId, input }, which is what Cron schedules and Webhooks publish.
Run this worker with node workflow-worker.ts. It uses the producer’s queue.
Register it in the worker with handlers: { fix }. For each job, workflow builds the graph from input and starts it under the job’s runId; the same input must build the same graph. Pass other start options, such as concurrency, budget, onQuota or timeoutMs, in start.
The stored job result lets the producer inspect the completed workflow.
API reference: QueueHandlerContext.
result.usage holds the run’s cumulative token usage. A failed, cancelled or rejected run fails the job; a paused or waiting run completes it. The summary in result.value retains the workflow status and its terminationCode: a gate refusal remains identifiable as rejected even though the job has status failed. See termination codes.
Resume a run
Section titled “Resume a run”A completed job ID cannot run again: enqueuing it returns the stored job. To continue a run, enqueue a new job ID with the same runId and the same input.
It prints pending until a worker runs the job. done tasks come from the checkpoint. Failed or interrupted tasks rerun only if the handler sets checkpoint: { store, version: "1", resume: "retry-incomplete" }: see Durable runs.
Approve or answer a paused run
Section titled “Approve or answer a paused run”start excludes decisions and answers: submit them from your application. Build the same workflow and call workflow.start() with checkpoint: { store, runId, version } from the job value, plus decisions (approvals) or answers (interactive tasks).
Run independent jobs
Section titled “Run independent jobs”This factory declares a separate ephemeral command for each task key.
Run both tasks together; their roots and sandboxes remain distinct.
The local provider here runs directly on the host without isolation. Each owned isolated task and queued job receives its own identity and root. Shared sandboxes remain sequential. Durable wrappers use a common workspace checkpoint coordinator. Borrowed workspaces remain the caller’s responsibility and are not automatically made restorable. Task caches contain JSON results; hits do not reproduce file writes.

