run.resume()
The .resume()
method continues execution of a suspended workflow step, optionally providing new context data that can be accessed by the step on the inputData property.
Usage
await run.resume({
runId: "abc-123",
stepId: "stepTwo",
context: {
secondValue: 100
}
});
Parameters
config:
object
Configuration for resuming the workflow
config
runId:
string
Unique identifier of the workflow run to resume
stepId:
string
ID of the suspended step to resume
context?:
Record<string, any>
New context data to inject into the step's inputData property
Returns
Promise<WorkflowResult>:
object
Result of the resumed workflow execution
Async/Await Flow
When a workflow is resumed, execution continues from the point immediately after the suspend()
call in the step’s execution function. This creates a natural flow in your code:
// Step definition with suspend point
const reviewStep = new Step({
id: "review",
execute: async ({ context, suspend }) => {
// First part of execution
const initialAnalysis = analyzeData(context.inputData.data);
if (initialAnalysis.needsReview) {
// Suspend execution here
await suspend({ analysis: initialAnalysis });
// This code runs after resume() is called
// context.inputData now contains any data provided during resume
return {
reviewedData: enhanceWithFeedback(initialAnalysis, context.inputData.feedback)
};
}
return { reviewedData: initialAnalysis };
}
});
const { runId, resume, start } = workflow.createRun();
await start({
inputData: {
data: "some data"
}
});
// Later, resume the workflow
const result = await resume({
runId: "workflow-123",
stepId: "review",
context: {
// This data will be available in `context.inputData`
feedback: "Looks good, but improve section 3"
}
});
Execution Flow
- The workflow runs until it hits
await suspend()
in thereview
step - The workflow state is persisted and execution pauses
- Later,
run.resume()
is called with new context data - Execution continues from the point after
suspend()
in thereview
step - The new context data (
feedback
) is available to the step on theinputData
property - The step completes and returns its result
- The workflow continues with subsequent steps
Error Handling
The resume function may throw several types of errors:
try {
await run.resume({
runId,
stepId: "stepTwo",
context: newData
});
} catch (error) {
if (error.message === "No snapshot found for workflow run") {
// Handle missing workflow state
}
if (error.message === "Failed to parse workflow snapshot") {
// Handle corrupted workflow state
}
}
Related