fix(workflow-sdk): Use the correct event group ID from the flow metadata (#9177)
This commit is contained in:
committed by
GitHub
parent
0c3e3ea88a
commit
a227d73e4f
@@ -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 = <TData = unknown, TResult = unknown>(
|
||||
|
||||
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
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user