From f9e8403d29ab38cbfa268948ceeaafd6625cf8ab Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" <37986729+carlos-r-l-rodrigues@users.noreply.github.com> Date: Mon, 7 Oct 2024 07:35:30 -0300 Subject: [PATCH] fix(orchestrator, workflows-sdk): skip async step (#9482) --- .../transaction/transaction-orchestrator.ts | 48 +++++++++---------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/packages/core/orchestration/src/transaction/transaction-orchestrator.ts b/packages/core/orchestration/src/transaction/transaction-orchestrator.ts index f4e95379a2..54637322f5 100644 --- a/packages/core/orchestration/src/transaction/transaction-orchestrator.ts +++ b/packages/core/orchestration/src/transaction/transaction-orchestrator.ts @@ -873,36 +873,32 @@ export class TransactionOrchestrator extends EventEmitter { promise = stepHandler() } - // TODO discussion why do we not await here, adding an await I wouldnt expect the test to fail but it does, maybe we should split the test to also test after everything is executed? - // cc test from engine redis promise .then(async (response: any) => { - if ( - !step.definition.backgroundExecution || - step.definition.nested - ) { - const eventName = DistributedTransactionEvent.STEP_AWAITING - transaction.emit(eventName, { step, transaction }) - - return - } - - if (this.hasExpired({ transaction, step }, Date.now())) { - await this.checkStepTimeout(transaction, step) - await this.checkTransactionTimeout( - transaction, - nextSteps.next.includes(step) ? nextSteps.next : [step] - ) - } - - let setResponse = true const output = response?.__type ? response.output : response + if (SkipStepResponse.isSkipStepResponse(output)) { await TransactionOrchestrator.skipStep(transaction, step) - setResponse = false - } + } else { + if ( + !step.definition.backgroundExecution || + step.definition.nested + ) { + const eventName = + DistributedTransactionEvent.STEP_AWAITING + transaction.emit(eventName, { step, transaction }) + + return + } + + if (this.hasExpired({ transaction, step }, Date.now())) { + await this.checkStepTimeout(transaction, step) + await this.checkTransactionTimeout( + transaction, + nextSteps.next.includes(step) ? nextSteps.next : [step] + ) + } - if (setResponse) { await TransactionOrchestrator.setStepSuccess( transaction, step, @@ -1148,7 +1144,9 @@ export class TransactionOrchestrator extends EventEmitter { queue.push({ obj: obj[key], level: [...level] }) } else if (key === "action") { if (actionNames.has(obj.action)) { - throw new Error(`Step ${obj.action} is already defined in workflow.`) + throw new Error( + `Step ${obj.action} is already defined in workflow.` + ) } actionNames.add(obj.action)