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
@@ -175,17 +175,21 @@ 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()
|
||||
@@ -194,9 +198,6 @@ export class WorkflowOrchestratorService {
|
||||
throw new Error("Workflow ID is required")
|
||||
}
|
||||
|
||||
context ??= {}
|
||||
context.transactionId ??= transactionId ?? ulid()
|
||||
|
||||
const events: FlowRunOptions["events"] = this.buildWorkflowEvents({
|
||||
customEventHandlers: eventHandlers,
|
||||
workflowId,
|
||||
@@ -210,7 +211,7 @@ export class WorkflowOrchestratorService {
|
||||
|
||||
const ret = await exportedWorkflow.run({
|
||||
input,
|
||||
throwOnError,
|
||||
throwOnError: false,
|
||||
logOnError,
|
||||
resultFrom,
|
||||
context,
|
||||
@@ -248,6 +249,10 @@ export class WorkflowOrchestratorService {
|
||||
await this.triggerParentStep(ret.transaction, result)
|
||||
}
|
||||
|
||||
if (throwOnError && ret.thrownError) {
|
||||
throw ret.thrownError
|
||||
}
|
||||
|
||||
return { acknowledgement, ...ret }
|
||||
}
|
||||
|
||||
@@ -299,13 +304,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)
|
||||
|
||||
@@ -324,7 +331,7 @@ export class WorkflowOrchestratorService {
|
||||
idempotencyKey: idempotencyKey_,
|
||||
context,
|
||||
resultFrom,
|
||||
throwOnError,
|
||||
throwOnError: false,
|
||||
logOnError,
|
||||
events,
|
||||
response: stepResponse,
|
||||
@@ -345,6 +352,10 @@ export class WorkflowOrchestratorService {
|
||||
await this.triggerParentStep(ret.transaction, result)
|
||||
}
|
||||
|
||||
if (throwOnError && ret.thrownError) {
|
||||
throw ret.thrownError
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
@@ -363,13 +374,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)
|
||||
|
||||
@@ -388,7 +401,7 @@ export class WorkflowOrchestratorService {
|
||||
idempotencyKey: idempotencyKey_,
|
||||
context,
|
||||
resultFrom,
|
||||
throwOnError,
|
||||
throwOnError: false,
|
||||
logOnError,
|
||||
events,
|
||||
response: stepResponse,
|
||||
@@ -409,6 +422,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