1 {"slug":"/references/workflows/classes/workflows.DistributedTransaction","title":"DistributedTransaction","frontmatter":{},"toc":[{"title":"Accessors","id":"accessors","level":2},{"title":"Constructors","id":"constructors","level":2},{"title":"Methods","id":"methods","level":2},{"title":"Properties","id":"properties","level":2},{"title":"isPartiallyCompleted","id":"ispartiallycompleted","level":2},{"title":"constructor","id":"constructor","level":2},{"title":"Parameters","id":"constructor-parameters","level":3}],"blocks":[{"kind":"markdown","html":"DistributedTransaction represents a distributed transaction, which is a transaction that is composed of multiple steps that are executed in a specific order."},{"kind":"heading","level":2,"text":"Accessors","id":"accessors"},{"kind":"linkList","items":[{"title":"isPartiallyCompleted","href":"/references/workflows/classes/workflows.DistributedTransaction#ispartiallycompleted"}]},{"kind":"heading","level":2,"text":"Constructors","id":"constructors"},{"kind":"linkList","items":[{"title":"constructor","href":"/references/workflows/classes/workflows.DistributedTransaction#constructor"}]},{"kind":"heading","level":2,"text":"Methods","id":"methods"},{"kind":"linkList","items":[{"title":"addError","href":"/references/workflows/DistributedTransaction/methods/workflows.DistributedTransaction.addError"},{"title":"addResponse","href":"/references/workflows/DistributedTransaction/methods/workflows.DistributedTransaction.addResponse"},{"title":"canInvoke","href":"/references/workflows/DistributedTransaction/methods/workflows.DistributedTransaction.canInvoke"},{"title":"canRevert","href":"/references/workflows/DistributedTransaction/methods/workflows.DistributedTransaction.canRevert"},{"title":"clearRetry","href":"/references/workflows/DistributedTransaction/methods/workflows.DistributedTransaction.clearRetry"},{"title":"clearStepTimeout","href":"/references/workflows/DistributedTransaction/methods/workflows.DistributedTransaction.clearStepTimeout"},{"title":"clearTransactionTimeout","href":"/references/workflows/DistributedTransaction/methods/workflows.DistributedTransaction.clearTransactionTimeout"},{"title":"getContext","href":"/references/workflows/DistributedTransaction/methods/workflows.DistributedTransaction.getContext"},{"title":"getErrors","href":"/references/workflows/DistributedTransaction/methods/workflows.DistributedTransaction.getErrors"},{"title":"getFlow","href":"/references/workflows/DistributedTransaction/methods/workflows.DistributedTransaction.getFlow"},{"title":"getState","href":"/references/workflows/DistributedTransaction/methods/workflows.DistributedTransaction.getState"},{"title":"getTemporaryData","href":"/references/workflows/DistributedTransaction/methods/workflows.DistributedTransaction.getTemporaryData"},{"title":"getTimeout","href":"/references/workflows/DistributedTransaction/methods/workflows.DistributedTransaction.getTimeout"},{"title":"hasFinished","href":"/references/workflows/DistributedTransaction/methods/workflows.DistributedTransaction.hasFinished"},{"title":"hasTemporaryData","href":"/references/workflows/DistributedTransaction/methods/workflows.DistributedTransaction.hasTemporaryData"},{"title":"hasTimeout","href":"/references/workflows/DistributedTransaction/methods/workflows.DistributedTransaction.hasTimeout"},{"title":"loadTransaction","href":"/references/workflows/DistributedTransaction/methods/workflows.DistributedTransaction.loadTransaction"},{"title":"saveCheckpoint","href":"/references/workflows/DistributedTransaction/methods/workflows.DistributedTransaction.saveCheckpoint"},{"title":"scheduleRetry","href":"/references/workflows/DistributedTransaction/methods/workflows.DistributedTransaction.scheduleRetry"},{"title":"scheduleStepTimeout","href":"/references/workflows/DistributedTransaction/methods/workflows.DistributedTransaction.scheduleStepTimeout"},{"title":"scheduleTransactionTimeout","href":"/references/workflows/DistributedTransaction/methods/workflows.DistributedTransaction.scheduleTransactionTimeout"},{"title":"setStorage","href":"/references/workflows/DistributedTransaction/methods/workflows.DistributedTransaction.setStorage"},{"title":"setTemporaryData","href":"/references/workflows/DistributedTransaction/methods/workflows.DistributedTransaction.setTemporaryData"}]},{"kind":"heading","level":2,"text":"Properties","id":"properties"},{"kind":"linkList","items":[{"title":"#private","href":"/references/workflows/classes/workflows.DistributedTransaction##private"},{"title":"context","href":"/references/workflows/classes/workflows.DistributedTransaction#context"},{"title":"errors","href":"/references/workflows/classes/workflows.DistributedTransaction#errors"},{"title":"flow","href":"/references/workflows/classes/workflows.DistributedTransaction#flow"},{"title":"handler","href":"/references/workflows/classes/workflows.DistributedTransaction#handler"},{"title":"keyPrefix","href":"/references/workflows/classes/workflows.DistributedTransaction#keyprefix"},{"title":"keyValueStore","href":"/references/workflows/classes/workflows.DistributedTransaction#keyvaluestore"},{"title":"modelId","href":"/references/workflows/classes/workflows.DistributedTransaction#modelid"},{"title":"payload","href":"/references/workflows/classes/workflows.DistributedTransaction#payload"},{"title":"runId","href":"/references/workflows/classes/workflows.DistributedTransaction#runid"},{"title":"transactionId","href":"/references/workflows/classes/workflows.DistributedTransaction#transactionid"}]},{"kind":"heading","level":2,"text":"isPartiallyCompleted","id":"ispartiallycompleted"},{"kind":"markdown","html":"**isPartiallyCompleted**:"},{"kind":"heading","level":2,"text":"constructor","id":"constructor"},{"kind":"heading","level":3,"text":"Parameters","id":"constructor-parameters"},{"kind":"typeList","sectionTitle":"constructor","types":[{"name":"flow","type":"[TransactionFlow](/references/workflows/types/workflows.TransactionFlow)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"modelId","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"options","type":"[TransactionModelOptions](/references/workflows/types/workflows.TransactionModelOptions)","description":"Defines the options for a transaction model, which are applicable to the entire workflow.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"timeout","type":"`number`","description":"The global timeout for the entire transaction workflow (in seconds).","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"store","type":"`boolean`","description":"If true, the state of the transaction will be persisted.\n\nLearn more in [this documentation](https://docs.medusajs.com/learn/fundamentals/workflows/store-executions).","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"retentionTime","type":"`number`","description":"The number of seconds that the workflow execution should be stored in the database.\n\nLearn more in [this documentation](https://docs.medusajs.com/learn/fundamentals/workflows/store-executions).","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"storeExecution","type":"`boolean`","description":"If true, the execution details of each step will be stored.","optional":true,"defaultValue":"","expandable":false,"children":[],"deprecated":{"is_deprecated":true,"description":"no longer needed."}},{"name":"idempotent","type":"`boolean`","description":"If true, the workflow will use the transaction ID as the key to ensure only-once execution","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"schedule","type":"`string` \\| [SchedulerOptions](/references/workflows/types/workflows.SchedulerOptions)","description":"Defines the workflow as a scheduled workflow that executes based on the cron configuration passed.\nThe value can either by a cron expression string, or an object that also allows to define the concurrency behavior.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"definition","type":"[TransactionStepsDefinition](/references/workflows/types/workflows.TransactionStepsDefinition)","description":"Defines the structure and behavior of a single step within a transaction workflow.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"uuid","type":"`string`","description":"A unique identifier for the transaction step.\nThis is set automatically when declaring a workflow with \"createWorkflow\"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"action","type":"`string`","description":"Specifies the action to be performed in this step.\n\"name\" is an alias for action when creating a workflow with \"createWorkflow\".","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"continueOnPermanentFailure","type":"`boolean`","description":"Indicates whether the workflow should continue even if there is a permanent failure in this step.\nIn case it is set to true, the current step will be marked as TransactionStepState.PERMANENT\\_FAILURE and the next steps will be executed.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"skipOnPermanentFailure","type":"`boolean` \\| `string`","description":"Indicates whether the workflow should skip all subsequent steps in case of a permanent failure in this step.\nIn case it is set to true, the next steps of the workflow will not be executed and their status will be marked as TransactionStepState.SKIPPED\\_FAILURE.\nIn case it is a string, the next steps until the step name provided will be skipped and the workflow will be resumed from the step provided.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"noCompensation","type":"`boolean`","description":"If true, no compensation action will be triggered for this step in case of a failure.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"maxRetries","type":"`number`","description":"The maximum number of times this step should be retried in case of temporary failures.\nThe default is 0 (no retries).","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"autoRetry","type":"`boolean`","description":"If true, the step will be retried automatically in case of a temporary failure.\nThe default is true.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"retryInterval","type":"`number`","description":"The interval (in seconds) between retry attempts after a temporary failure.\nThe default is to retry immediately.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"retryIntervalAwaiting","type":"`number`","description":"The interval (in seconds) to retry a step even if its status is \"TransactionStepStatus.WAITING\".","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"maxAwaitingRetries","type":"`number`","description":"The maximum number of times to retry a step even if its status is \"TransactionStepStatus.WAITING\".","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"timeout","type":"`number`","description":"The maximum amount of time (in seconds) to wait for this step to complete.\nThis is NOT an execution timeout, the step will always be executed and wait for its response.\nIf the response is not received within the timeout set, it will be marked as \"TransactionStepStatus.TIMEOUT\" and the workflow will be reverted as soon as it receives the response.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"async","type":"`boolean`","description":"If true, the step is executed asynchronously. This means that the workflow will not wait for the response of this step.\nAsync steps require to have their responses set using \"setStepSuccess\" or \"setStepFailure\", unless it is combined with \"backgroundExecution: true\".\nIf combined with a timeout, and any response is not set within that interval, the step will be marked as \"TransactionStepStatus.TIMEOUT\" and the workflow will be reverted immediately.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"nested","type":"`boolean`","description":"It flags where the step contains a sub transaction inside itself.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"backgroundExecution","type":"`boolean`","description":"It applies to \"async\" steps only, allowing them to run in the background and automatically complete without external intervention.\nIt 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.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"compensateAsync","type":"`boolean`","description":"If true, the compensation function for this step is executed asynchronously. Which means, the response has to be set using \"setStepSuccess\" or \"setStepFailure\".","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"noWait","type":"`boolean`","description":"If true, the workflow will not wait for their sibling steps to complete before moving to the next step.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"saveResponse","type":"`boolean`","description":"If true, the response of this step will be stored.\nDefault is true.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"next","type":"[TransactionStepsDefinition](/references/workflows/types/workflows.TransactionStepsDefinition) \\| [TransactionStepsDefinition](/references/workflows/types/workflows.TransactionStepsDefinition)[]","description":"Defines the next step(s) to execute after this step. Can be a single step or an array of steps.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"store","type":"`boolean`","description":"Whether we need to store checkpoint at this step.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"transactionId","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"runId","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`object`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"eventGroupId","type":"`string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"parentIdempotencyKey","type":"`string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"cancelingFromParentStep","type":"`boolean`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"sourcePath","type":"`string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"preventReleaseEvents","type":"`boolean`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"parentStepIdempotencyKey","type":"`string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"hasAsyncSteps","type":"`boolean`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"hasFailedSteps","type":"`boolean`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"hasSkippedOnFailureSteps","type":"`boolean`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"hasWaitingSteps","type":"`boolean`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"hasSkippedSteps","type":"`boolean`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"hasRevertedSteps","type":"`boolean`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"timedOutAt","type":"`number` \\| `null`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"startedAt","type":"`number`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"cancelledAt","type":"`number`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"temporaryFailedAt","type":"`number` \\| `null`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"state","type":"[TransactionState](/references/workflows/enums/workflows.TransactionState)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"NOT_STARTED","type":"`\"not_started\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"INVOKING","type":"`\"invoking\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"WAITING_TO_COMPENSATE","type":"`\"waiting_to_compensate\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"COMPENSATING","type":"`\"compensating\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"DONE","type":"`\"done\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"REVERTED","type":"`\"reverted\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"FAILED","type":"`\"failed\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"steps","type":"`object`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"_v","type":"`number`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"handler","type":"[TransactionStepHandler](/references/workflows/types/workflows.TransactionStepHandler)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"payload","type":"`any`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"errors","type":"[TransactionStepError](/references/workflows/classes/workflows.TransactionStepError)[]","description":"","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"action","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"handlerType","type":"[TransactionHandlerType](/references/workflows/enums/workflows.TransactionHandlerType)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"INVOKE","type":"`\"invoke\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"COMPENSATE","type":"`\"compensate\"`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"error","type":"`any`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"context","type":"[TransactionContext](/references/workflows/classes/workflows.TransactionContext)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"payload","type":"`unknown`","description":"Object containing the initial payload.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"invoke","type":"`Record<string, unknown>`","description":"Object containing responses of Invoke handlers on steps flagged with saveResponse.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"compensate","type":"`Record<string, unknown>`","description":"Object containing responses of Compensate handlers on steps flagged with saveResponse.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]},{"kind":"typeList","sectionTitle":"DistributedTransaction","types":[{"name":"#private","type":"`any`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"context","type":"`any`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"errors","type":"`any`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"flow","type":"`any`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"handler","type":"[TransactionStepHandler](/references/workflows/types/workflows.TransactionStepHandler)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"keyPrefix","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"keyValueStore","type":"`any`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"modelId","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"payload","type":"`any`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"runId","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"transactionId","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}