chore: idempotent cart operations (#13236)
* chore(core-flows): idempotent cart operations * changeset * add tests * revert * revert route * promo test * skip bugs * fix test * tests * avoid workflow name conflict * prevent nested workflow from being deleted until the top level parent finishes * remove unused setTimeout * update changeset * rm comments --------- Co-authored-by: adrien2p <adrien.deperetti@gmail.com>
This commit is contained in:
committed by
GitHub
parent
b111d01898
commit
9412669e65
@@ -37,6 +37,7 @@ import {
|
||||
TransactionStepTimeoutError,
|
||||
TransactionTimeoutError,
|
||||
} from "./errors"
|
||||
import { Context } from "@medusajs/types"
|
||||
|
||||
/**
|
||||
* @class TransactionOrchestrator is responsible for managing and executing distributed transactions.
|
||||
@@ -1380,7 +1381,8 @@ export class TransactionOrchestrator extends EventEmitter {
|
||||
|
||||
private createTransactionFlow(
|
||||
transactionId: string,
|
||||
flowMetadata?: TransactionFlow["metadata"]
|
||||
flowMetadata?: TransactionFlow["metadata"],
|
||||
context?: Context
|
||||
): TransactionFlow {
|
||||
const [steps, features] = TransactionOrchestrator.buildSteps(
|
||||
this.definition
|
||||
@@ -1390,7 +1392,7 @@ export class TransactionOrchestrator extends EventEmitter {
|
||||
modelId: this.id,
|
||||
options: this.options,
|
||||
transactionId: transactionId,
|
||||
runId: ulid(),
|
||||
runId: context?.runId ?? ulid(),
|
||||
metadata: flowMetadata,
|
||||
hasAsyncSteps: features.hasAsyncSteps,
|
||||
hasFailedSteps: false,
|
||||
@@ -1541,12 +1543,14 @@ export class TransactionOrchestrator extends EventEmitter {
|
||||
handler,
|
||||
payload,
|
||||
flowMetadata,
|
||||
context,
|
||||
onLoad,
|
||||
}: {
|
||||
transactionId: string
|
||||
handler: TransactionStepHandler
|
||||
payload?: unknown
|
||||
flowMetadata?: TransactionFlow["metadata"]
|
||||
context?: Context
|
||||
onLoad?: (transaction: DistributedTransactionType) => Promise<void> | void
|
||||
}): Promise<DistributedTransactionType> {
|
||||
const existingTransaction =
|
||||
@@ -1555,7 +1559,11 @@ export class TransactionOrchestrator extends EventEmitter {
|
||||
let newTransaction = false
|
||||
let modelFlow: TransactionFlow
|
||||
if (!existingTransaction) {
|
||||
modelFlow = this.createTransactionFlow(transactionId, flowMetadata)
|
||||
modelFlow = this.createTransactionFlow(
|
||||
transactionId,
|
||||
flowMetadata,
|
||||
context
|
||||
)
|
||||
newTransaction = true
|
||||
} else {
|
||||
modelFlow = existingTransaction.flow
|
||||
|
||||
@@ -362,6 +362,7 @@ export class LocalWorkflow {
|
||||
handler: handler(this.container_, context),
|
||||
payload: input,
|
||||
flowMetadata,
|
||||
context,
|
||||
onLoad: this.onLoad.bind(this),
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user