Steps

context.invoke

context.invoke() triggers another workflow run and pauses until the invoked workflow finishes.

The calling workflow resumes once the invoked workflow either succeeds, fails, or is canceled.

Workflows can only invoke other workflows that were served together in the same serveMany route. For details, see Invoke other workflows.

Arguments

workflowbodyfunctionrequired

The workflow definition to invoke. Must be a workflow exposed under the same serveMany.

bodybodyany

The payload to send to the invoked workflow. This value will be set as context.requestPayload in the invoked workflow.

headersbodyobject

Optional HTTP headers to forward to the invoked workflow. This value will be set as context.headers in the invoked workflow.

workflowRunIdbodystring

Override the workflow run ID for the invoked workflow. Defaults to a new ID if not specified.

retriesbodynumber

Number of retry attempts configuration of the invoked workflow. Defaults to 3. Retries use exponential backoff.

retryDelaybodynumber|string

Delay between retries of the invoked workflow.

flowControlbodyobject

Flow control configuration of the invoked workflow.

See Flow Control for details.

Response

bodyany

The response body returned by the invoked workflow.

isFailedboolean

true if the invoked workflow completed with failure.

isCanceledboolean

true if the invoked workflow was canceled before completion.

Usage

const { body, isFailed, isCanceled } = await context.invoke(  "invoke another workflow",  {    workflow: anotherWorkflow,    body: "test",    header: {...}, // headers to pass to anotherWorkflow (optional)    retries,       // number of retries (optional, default: 3)    retryDelay,    // delay between retries (optional, uses exponential backoff by default)    flowControl,   // flow control settings (optional)    workflowRunId  // workflowRunId to set (optional)  });
Loading search…