fix(): Identify step that should require a save on checkpoint (#14037)
* fix(): Identify step that force save checkpoint * Create sour-peas-provide.md
This commit is contained in:
committed by
GitHub
parent
4e1c474dfa
commit
1ea932a56f
@@ -28,9 +28,7 @@ const step_1_retry_interval = createStep(
|
||||
|
||||
// Fail until we reach the target attempt
|
||||
if (attemptCount < input.attemptToSucceedOn) {
|
||||
throw new Error(
|
||||
`Step 1 failed on attempt ${attemptCount}, will retry`
|
||||
)
|
||||
throw new Error(`Step 1 failed on attempt ${attemptCount}, will retry`)
|
||||
}
|
||||
|
||||
return new StepResponse({
|
||||
@@ -47,7 +45,7 @@ const step_2_after_retry = createStep(
|
||||
name: "step_2_after_retry",
|
||||
async: true,
|
||||
},
|
||||
async (input) => {
|
||||
async (input: any) => {
|
||||
retryIntervalStep2InvokeMock(input)
|
||||
|
||||
return new StepResponse({
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
/**
|
||||
* Test fixture for workflow with retry interval
|
||||
* Tests that steps with retry intervals properly retry after failures
|
||||
*/
|
||||
|
||||
import {
|
||||
createStep,
|
||||
createWorkflow,
|
||||
StepResponse,
|
||||
WorkflowResponse,
|
||||
} from "@medusajs/framework/workflows-sdk"
|
||||
|
||||
// Mock counters to track execution attempts
|
||||
export const retryIntervalStep1InvokeMock = jest.fn()
|
||||
export const retryIntervalStep2InvokeMock = jest.fn()
|
||||
export const retryIntervalStep0InvokeMock = jest.fn()
|
||||
|
||||
const step_0_retry_interval = createStep(
|
||||
{
|
||||
name: "step_0_sync_retry_interval",
|
||||
},
|
||||
async (input: any) => {
|
||||
retryIntervalStep0InvokeMock(input)
|
||||
return new StepResponse(input)
|
||||
}
|
||||
)
|
||||
|
||||
// Step 1: Fails first 2 times, succeeds on 3rd attempt
|
||||
const step_1_retry_interval = createStep(
|
||||
{
|
||||
name: "step_1_sync_retry_interval",
|
||||
retryInterval: 1, // 1 second retry interval
|
||||
maxRetries: 3,
|
||||
},
|
||||
async (input: { attemptToSucceedOn: number }) => {
|
||||
const attemptCount = retryIntervalStep1InvokeMock.mock.calls.length + 1
|
||||
retryIntervalStep1InvokeMock(input)
|
||||
|
||||
// Fail until we reach the target attempt
|
||||
if (attemptCount < input.attemptToSucceedOn) {
|
||||
throw new Error(`Step 1 failed on attempt ${attemptCount}, will retry`)
|
||||
}
|
||||
|
||||
return new StepResponse({
|
||||
success: true,
|
||||
attempts: attemptCount,
|
||||
step: "step_1",
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
// Step 2: Always succeeds (to verify workflow continues after retry)
|
||||
const step_2_after_retry = createStep(
|
||||
{
|
||||
name: "step_2_sync_after_retry",
|
||||
},
|
||||
async (input: any) => {
|
||||
retryIntervalStep2InvokeMock(input)
|
||||
|
||||
return new StepResponse({
|
||||
success: true,
|
||||
step: "step_2",
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
export const workflowRetryIntervalId = "workflow_sync_retry_interval_test"
|
||||
|
||||
createWorkflow(
|
||||
{
|
||||
name: workflowRetryIntervalId,
|
||||
retentionTime: 600, // Keep for 10 minutes for debugging
|
||||
},
|
||||
function (input: { attemptToSucceedOn: number }) {
|
||||
const step0Result = step_0_retry_interval(input)
|
||||
const step1Result = step_1_retry_interval(step0Result)
|
||||
const step2Result = step_2_after_retry({ step1Result })
|
||||
|
||||
return new WorkflowResponse({
|
||||
step1: step1Result,
|
||||
step2: step2Result,
|
||||
})
|
||||
}
|
||||
)
|
||||
Reference in New Issue
Block a user