Skip to content

Commit

Permalink
fix(orchestrator, workflows-sdk): skip async step (#9482)
Browse files Browse the repository at this point in the history
  • Loading branch information
carlos-r-l-rodrigues authored Oct 7, 2024
1 parent ad3524f commit f9e8403
Showing 1 changed file with 23 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit f9e8403

Please sign in to comment.