feat: run nested async workflows (#9119)
This commit is contained in:
committed by
GitHub
parent
0bcdcccbe2
commit
ef8dc4087e
@@ -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] || {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user