chore(orchestration): add support for autoRetry, maxAwaitingRetries, retryStep (#13391)

RESOLVES CORE-1163
RESOLVES CORE-1164

**What**

### Add support for non auto retryable steps.

When marking a step with `maxRetries`, when it will fail it will be marked as temporary failure and then retry itself automatically. Thats the default behaviour, if you now add `autoRetry: false`, when the step will fail it will be marked as temporary failure but not retry automatically. you can now call the workflow engine run to resume the workflow from the failing step to be retried.

### Add support for `maxAwaitingRetries`

When setting `retyIntervalAwaiting` a step that is awaiting will be retried after the specified interval without maximun retry. Now you can set `maxAwaitingRetries` to force a maximum awaiting retry number

### Add support to manually retry an awaiting step

In some scenario, either a machine dies while a step is executing or a step is taking longer than expected, you can now call `retryStep` on the workflow engine to force a retry of the step that is supposedly stucked
This commit is contained in:
Adrien de Peretti
2025-09-08 14:46:30 +02:00
committed by GitHub
parent ac5e23b96c
commit d7692100e7
28 changed files with 1366 additions and 64 deletions

View File

@@ -0,0 +1,56 @@
import {
createStep,
createWorkflow,
StepResponse,
} from "@medusajs/framework/workflows-sdk"
const step1InvokeMock = jest.fn((input) => {
input.test = "test"
return new StepResponse(input, { compensate: 123 })
})
const step1CompensateMock = jest.fn((compensateInput) => {
if (!compensateInput) {
return
}
return new StepResponse({
reverted: true,
})
})
const step2InvokeMock = jest.fn((input) => {
throw new Error("Temporary failure")
})
const step2CompensateMock = jest.fn((compensateInput) => {
if (!compensateInput) {
return
}
return new StepResponse({
reverted: true,
})
})
export {
step1CompensateMock,
step1InvokeMock,
step2CompensateMock,
step2InvokeMock,
}
const step_1 = createStep("step_1", step1InvokeMock, step1CompensateMock)
const step_2 = createStep("step_2", step2InvokeMock, step2CompensateMock)
createWorkflow("workflow_1_auto_retries", function (input) {
step_1(input)
const ret2 = step_2({ hey: "oh" }).config({
async: true,
maxRetries: 2,
})
return ret2
})

View File

@@ -0,0 +1,57 @@
import {
createStep,
createWorkflow,
StepResponse,
} from "@medusajs/framework/workflows-sdk"
const step1InvokeMock = jest.fn((input) => {
input.test = "test"
return new StepResponse(input, { compensate: 123 })
})
const step1CompensateMock = jest.fn((compensateInput) => {
if (!compensateInput) {
return
}
return new StepResponse({
reverted: true,
})
})
const step2InvokeMock = jest.fn((input) => {
throw new Error("Temporary failure")
})
const step2CompensateMock = jest.fn((compensateInput) => {
if (!compensateInput) {
return
}
return new StepResponse({
reverted: true,
})
})
export {
step1CompensateMock,
step1InvokeMock,
step2CompensateMock,
step2InvokeMock,
}
const step_1 = createStep("step_1", step1InvokeMock, step1CompensateMock)
const step_2 = createStep("step_2", step2InvokeMock, step2CompensateMock)
createWorkflow("workflow_1_auto_retries_false", function (input) {
step_1(input)
const ret2 = step_2({ hey: "oh" }).config({
async: true,
maxRetries: 2,
autoRetry: false,
})
return ret2
})

View File

@@ -0,0 +1,60 @@
import {
createStep,
createWorkflow,
StepResponse,
} from "@medusajs/framework/workflows-sdk"
const step1InvokeMock = jest.fn((input) => {
input.test = "test"
return new StepResponse(input, { compensate: 123 })
})
const step1CompensateMock = jest.fn((compensateInput) => {
if (!compensateInput) {
return
}
return new StepResponse({
reverted: true,
})
})
const step2InvokeMock = jest.fn(async (input, context) => {
if (context.metadata.attempt === 1) {
await new Promise((resolve) => setTimeout(resolve, 100000))
return new StepResponse("success after 100 seconds")
}
return new StepResponse("success")
})
const step2CompensateMock = jest.fn((compensateInput) => {
if (!compensateInput) {
return
}
return new StepResponse({
reverted: true,
})
})
export {
step1CompensateMock,
step1InvokeMock,
step2CompensateMock,
step2InvokeMock,
}
const step_1 = createStep("step_1", step1InvokeMock, step1CompensateMock)
const step_2 = createStep("step_2", step2InvokeMock, step2CompensateMock)
createWorkflow("workflow_1_manual_retry_step", function (input) {
step_1(input)
const ret2 = step_2({ hey: "oh" }).config({
async: true,
})
return ret2
})