chore: ensure the event group id is kept for async workflow (#7668)
* chore: ensure the event group id is kept for async workflow * revert test * fix tests --------- Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com> Co-authored-by: Riqwan Thamir <rmthamir@gmail.com>
This commit is contained in:
committed by
GitHub
parent
3d72002c28
commit
afae395fea
@@ -28,6 +28,10 @@ export type TransactionFlow = {
|
||||
options?: TransactionModelOptions
|
||||
definition: TransactionStepsDefinition
|
||||
transactionId: string
|
||||
metadata?: {
|
||||
eventGroupId?: string
|
||||
[key: string]: unknown
|
||||
}
|
||||
hasAsyncSteps: boolean
|
||||
hasFailedSteps: boolean
|
||||
hasWaitingSteps: boolean
|
||||
@@ -839,7 +843,7 @@ export class TransactionOrchestrator extends EventEmitter {
|
||||
await this.executeNext(transaction)
|
||||
}
|
||||
|
||||
private createTransactionFlow(transactionId: string): TransactionFlow {
|
||||
private createTransactionFlow(transactionId: string, flowMetadata?: TransactionFlow['metadata']): TransactionFlow {
|
||||
const [steps, features] = TransactionOrchestrator.buildSteps(
|
||||
this.definition
|
||||
)
|
||||
@@ -864,6 +868,7 @@ export class TransactionOrchestrator extends EventEmitter {
|
||||
modelId: this.id,
|
||||
options: this.options,
|
||||
transactionId: transactionId,
|
||||
metadata: flowMetadata,
|
||||
hasAsyncSteps,
|
||||
hasFailedSteps: false,
|
||||
hasSkippedSteps: false,
|
||||
@@ -1006,11 +1011,13 @@ export class TransactionOrchestrator extends EventEmitter {
|
||||
* @param transactionId - unique identifier of the transaction
|
||||
* @param handler - function to handle action of the transaction
|
||||
* @param payload - payload to be passed to all the transaction steps
|
||||
* @param flowMetadata - flow metadata which can include event group id for example
|
||||
*/
|
||||
public async beginTransaction(
|
||||
transactionId: string,
|
||||
handler: TransactionStepHandler,
|
||||
payload?: unknown
|
||||
payload?: unknown,
|
||||
flowMetadata?: TransactionFlow["metadata"]
|
||||
): Promise<DistributedTransaction> {
|
||||
const existingTransaction =
|
||||
await TransactionOrchestrator.loadTransactionById(this.id, transactionId)
|
||||
@@ -1018,7 +1025,7 @@ export class TransactionOrchestrator extends EventEmitter {
|
||||
let newTransaction = false
|
||||
let modelFlow: TransactionFlow
|
||||
if (!existingTransaction) {
|
||||
modelFlow = this.createTransactionFlow(transactionId)
|
||||
modelFlow = this.createTransactionFlow(transactionId, flowMetadata)
|
||||
newTransaction = true
|
||||
} else {
|
||||
modelFlow = existingTransaction.flow
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
DistributedTransaction,
|
||||
DistributedTransactionEvent,
|
||||
DistributedTransactionEvents,
|
||||
TransactionFlow,
|
||||
TransactionModelOptions,
|
||||
TransactionOrchestrator,
|
||||
TransactionStepsDefinition,
|
||||
@@ -332,7 +333,8 @@ export class LocalWorkflow {
|
||||
uniqueTransactionId: string,
|
||||
input?: unknown,
|
||||
context?: Context,
|
||||
subscribe?: DistributedTransactionEvents
|
||||
subscribe?: DistributedTransactionEvents,
|
||||
flowMetadata?: TransactionFlow["metadata"]
|
||||
) {
|
||||
if (this.flow.hasChanges) {
|
||||
this.commit()
|
||||
@@ -343,7 +345,8 @@ export class LocalWorkflow {
|
||||
const transaction = await orchestrator.beginTransaction(
|
||||
uniqueTransactionId,
|
||||
handler(this.container_, context),
|
||||
input
|
||||
input,
|
||||
flowMetadata
|
||||
)
|
||||
|
||||
const { cleanUpEventListeners } = this.registerEventCallbacks({
|
||||
|
||||
Reference in New Issue
Block a user