feat: run nested async workflows (#9119)

This commit is contained in:
Carlos R. L. Rodrigues
2024-09-16 10:06:45 -03:00
committed by GitHub
parent 0bcdcccbe2
commit ef8dc4087e
23 changed files with 295 additions and 100 deletions

View File

@@ -795,7 +795,10 @@ export class TransactionOrchestrator extends EventEmitter {
this
)
.then(async (response: any) => {
if (!step.definition.backgroundExecution) {
if (
!step.definition.backgroundExecution ||
step.definition.nested
) {
const eventName = DistributedTransactionEvent.STEP_AWAITING
transaction.emit(eventName, { step, transaction })
@@ -825,6 +828,7 @@ export class TransactionOrchestrator extends EventEmitter {
)
}
// check nested flow
await transaction.scheduleRetry(
step,
step.definition.retryInterval ?? 0
@@ -1033,6 +1037,7 @@ export class TransactionOrchestrator extends EventEmitter {
hasAsyncSteps: false,
hasStepTimeouts: false,
hasRetriesTimeout: false,
hasNestedTransactions: false,
}
while (queue.length > 0) {
@@ -1073,6 +1078,10 @@ export class TransactionOrchestrator extends EventEmitter {
features.hasRetriesTimeout = true
}
if (definitionCopy.nested) {
features.hasNestedTransactions = true
}
states[id] = Object.assign(
new TransactionStep(),
existingSteps?.[id] || {

View File

@@ -65,6 +65,11 @@ export type TransactionStepsDefinition = {
*/
async?: boolean
/**
* It flags where the step contains a sub transaction inside itself.
*/
nested?: boolean
/**
* It applies to "async" steps only, allowing them to run in the background and automatically complete without external intervention.
* It is ideal for time-consuming tasks that will be complete after the execution, contrasting with standard "async" operations that require a response to be set in a later stage.
@@ -237,6 +242,7 @@ export type TransactionFlow = {
transactionId: string
metadata?: {
eventGroupId?: string
parentIdempotencyKey?: string
[key: string]: unknown
}
hasAsyncSteps: boolean