diff --git a/packages/core/workflows-sdk/src/helper/workflow-export.ts b/packages/core/workflows-sdk/src/helper/workflow-export.ts index f5350ff202..a2ff478560 100644 --- a/packages/core/workflows-sdk/src/helper/workflow-export.ts +++ b/packages/core/workflows-sdk/src/helper/workflow-export.ts @@ -9,9 +9,9 @@ import { import { Context, LoadedModule, MedusaContainer } from "@medusajs/types" import { ContainerRegistrationKeys, + isPresent, MedusaContextType, Modules, - isPresent, } from "@medusajs/utils" import { EOL } from "os" import { ulid } from "ulid" @@ -88,7 +88,7 @@ function createContextualWorkflowRunner< const { eventGroupId, parentStepIdempotencyKey } = context - attachOnFinishReleaseEvents(events, eventGroupId!, flow, { logOnError }) + attachOnFinishReleaseEvents(events, flow, { logOnError }) const flowMetadata = { eventGroupId, @@ -493,7 +493,6 @@ export const exportWorkflow = ( function attachOnFinishReleaseEvents( events: DistributedTransactionEvents = {}, - eventGroupId: string, flow: LocalWorkflow, { logOnError, @@ -509,6 +508,7 @@ function attachOnFinishReleaseEvents( errors?: unknown[] }) => { const { transaction } = args + const flowEventGroupId = transaction.getFlow().metadata?.eventGroupId const logger = (flow.container as MedusaContainer).resolve( @@ -541,7 +541,7 @@ function attachOnFinishReleaseEvents( { allowUnregistered: true } ) - if (!eventBusService || !eventGroupId) { + if (!eventBusService || !flowEventGroupId) { return } @@ -549,17 +549,17 @@ function attachOnFinishReleaseEvents( if (failedStatus.includes(transaction.getState())) { return await eventBusService - .clearGroupedEvents(eventGroupId) + .clearGroupedEvents(flowEventGroupId) .catch(() => { logger.warn( - `Failed to clear events for eventGroupId - ${eventGroupId}` + `Failed to clear events for eventGroupId - ${flowEventGroupId}` ) }) } - await eventBusService.releaseGroupedEvents(eventGroupId).catch((e) => { + await eventBusService.releaseGroupedEvents(flowEventGroupId).catch((e) => { logger.error( - `Failed to release grouped events for eventGroupId: ${eventGroupId}`, + `Failed to release grouped events for eventGroupId: ${flowEventGroupId}`, e )