fix(orchestration): fix set step failure (#10031)
What: - copy data before saving checkpoint - removed unused data format function - properly handle registerStepFailure to not throw - emit onFinish event even when execution failed
This commit is contained in:
committed by
GitHub
parent
7794faf49e
commit
1eef324af3
@@ -3,11 +3,14 @@ import {
|
||||
createWorkflow,
|
||||
StepResponse,
|
||||
} from "@medusajs/framework/workflows-sdk"
|
||||
import { setTimeout } from "timers/promises"
|
||||
|
||||
const step_1 = createStep(
|
||||
"step_1",
|
||||
jest.fn((input) => {
|
||||
jest.fn(async (input) => {
|
||||
input.test = "test"
|
||||
await setTimeout(200)
|
||||
|
||||
return new StepResponse(input, { compensate: 123 })
|
||||
}),
|
||||
jest.fn((compensateInput) => {
|
||||
@@ -27,9 +30,7 @@ createWorkflow(
|
||||
timeout: 0.1, // 0.1 second
|
||||
},
|
||||
function (input) {
|
||||
const resp = step_1(input).config({
|
||||
async: true,
|
||||
})
|
||||
const resp = step_1(input)
|
||||
|
||||
return resp
|
||||
}
|
||||
|
||||
@@ -131,17 +131,20 @@ export class WorkflowOrchestratorService {
|
||||
options?: WorkflowOrchestratorRunOptions<T>,
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
) {
|
||||
let {
|
||||
const {
|
||||
input,
|
||||
context,
|
||||
transactionId,
|
||||
resultFrom,
|
||||
throwOnError,
|
||||
logOnError,
|
||||
events: eventHandlers,
|
||||
container,
|
||||
} = options ?? {}
|
||||
|
||||
let { throwOnError, context } = options ?? {}
|
||||
throwOnError ??= true
|
||||
context ??= {}
|
||||
context.transactionId ??= transactionId ?? ulid()
|
||||
|
||||
const workflowId = isString(workflowIdOrWorkflow)
|
||||
? workflowIdOrWorkflow
|
||||
: workflowIdOrWorkflow.getName()
|
||||
@@ -153,9 +156,6 @@ export class WorkflowOrchestratorService {
|
||||
)
|
||||
}
|
||||
|
||||
context ??= {}
|
||||
context.transactionId ??= transactionId ?? ulid()
|
||||
|
||||
const events: FlowRunOptions["events"] = this.buildWorkflowEvents({
|
||||
customEventHandlers: eventHandlers,
|
||||
workflowId,
|
||||
@@ -172,7 +172,7 @@ export class WorkflowOrchestratorService {
|
||||
|
||||
const ret = await exportedWorkflow.run({
|
||||
input,
|
||||
throwOnError,
|
||||
throwOnError: false,
|
||||
logOnError,
|
||||
resultFrom,
|
||||
context,
|
||||
@@ -210,6 +210,10 @@ export class WorkflowOrchestratorService {
|
||||
await this.triggerParentStep(ret.transaction, result)
|
||||
}
|
||||
|
||||
if (throwOnError && ret.thrownError) {
|
||||
throw ret.thrownError
|
||||
}
|
||||
|
||||
return { acknowledgement, ...ret }
|
||||
}
|
||||
|
||||
@@ -262,13 +266,15 @@ export class WorkflowOrchestratorService {
|
||||
) {
|
||||
const {
|
||||
context,
|
||||
throwOnError,
|
||||
logOnError,
|
||||
resultFrom,
|
||||
container,
|
||||
events: eventHandlers,
|
||||
} = options ?? {}
|
||||
|
||||
let { throwOnError } = options ?? {}
|
||||
throwOnError ??= true
|
||||
|
||||
const [idempotencyKey_, { workflowId, transactionId }] =
|
||||
this.buildIdempotencyKeyAndParts(idempotencyKey)
|
||||
|
||||
@@ -287,7 +293,7 @@ export class WorkflowOrchestratorService {
|
||||
idempotencyKey: idempotencyKey_,
|
||||
context,
|
||||
resultFrom,
|
||||
throwOnError,
|
||||
throwOnError: false,
|
||||
logOnError,
|
||||
events,
|
||||
response: stepResponse,
|
||||
@@ -308,6 +314,10 @@ export class WorkflowOrchestratorService {
|
||||
await this.triggerParentStep(ret.transaction, result)
|
||||
}
|
||||
|
||||
if (throwOnError && ret.thrownError) {
|
||||
throw ret.thrownError
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
@@ -326,13 +336,15 @@ export class WorkflowOrchestratorService {
|
||||
) {
|
||||
const {
|
||||
context,
|
||||
throwOnError,
|
||||
logOnError,
|
||||
resultFrom,
|
||||
container,
|
||||
events: eventHandlers,
|
||||
} = options ?? {}
|
||||
|
||||
let { throwOnError } = options ?? {}
|
||||
throwOnError ??= true
|
||||
|
||||
const [idempotencyKey_, { workflowId, transactionId }] =
|
||||
this.buildIdempotencyKeyAndParts(idempotencyKey)
|
||||
|
||||
@@ -351,7 +363,7 @@ export class WorkflowOrchestratorService {
|
||||
idempotencyKey: idempotencyKey_,
|
||||
context,
|
||||
resultFrom,
|
||||
throwOnError,
|
||||
throwOnError: false,
|
||||
logOnError,
|
||||
events,
|
||||
response: stepResponse,
|
||||
@@ -372,6 +384,10 @@ export class WorkflowOrchestratorService {
|
||||
await this.triggerParentStep(ret.transaction, result)
|
||||
}
|
||||
|
||||
if (throwOnError && ret.thrownError) {
|
||||
throw ret.thrownError
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user