fix(workflow-sdk): Use the correct event group ID from the flow metadata (#9177)
This commit is contained in:
1 parent
0c3e3ea88a
commit
a227d73e4f
1 file changed
+8
-8
@@ -9,9 +9,9 @@ import {
|
|||||||
import { Context, LoadedModule, MedusaContainer } from "@medusajs/types"
|
import { Context, LoadedModule, MedusaContainer } from "@medusajs/types"
|
||||||
import {
|
import {
|
||||||
ContainerRegistrationKeys,
|
ContainerRegistrationKeys,
|
||||||
|
isPresent,
|
||||||
MedusaContextType,
|
MedusaContextType,
|
||||||
Modules,
|
Modules,
|
||||||
isPresent,
|
|
||||||
} from "@medusajs/utils"
|
} from "@medusajs/utils"
|
||||||
import { EOL } from "os"
|
import { EOL } from "os"
|
||||||
import { ulid } from "ulid"
|
import { ulid } from "ulid"
|
||||||
@@ -88,7 +88,7 @@ function createContextualWorkflowRunner<
|
|||||||
|
|
||||||
const { eventGroupId, parentStepIdempotencyKey } = context
|
const { eventGroupId, parentStepIdempotencyKey } = context
|
||||||
|
|
||||||
attachOnFinishReleaseEvents(events, eventGroupId!, flow, { logOnError })
|
attachOnFinishReleaseEvents(events, flow, { logOnError })
|
||||||
|
|
||||||
const flowMetadata = {
|
const flowMetadata = {
|
||||||
eventGroupId,
|
eventGroupId,
|
||||||
@@ -493,7 +493,6 @@ export const exportWorkflow = <TData = unknown, TResult = unknown>(
|
|||||||
|
|
||||||
function attachOnFinishReleaseEvents(
|
function attachOnFinishReleaseEvents(
|
||||||
events: DistributedTransactionEvents = {},
|
events: DistributedTransactionEvents = {},
|
||||||
eventGroupId: string,
|
|
||||||
flow: LocalWorkflow,
|
flow: LocalWorkflow,
|
||||||
{
|
{
|
||||||
logOnError,
|
logOnError,
|
||||||
@@ -509,6 +508,7 @@ function attachOnFinishReleaseEvents(
|
|||||||
errors?: unknown[]
|
errors?: unknown[]
|
||||||
}) => {
|
}) => {
|
||||||
const { transaction } = args
|
const { transaction } = args
|
||||||
|
const flowEventGroupId = transaction.getFlow().metadata?.eventGroupId
|
||||||
|
|
||||||
const logger =
|
const logger =
|
||||||
(flow.container as MedusaContainer).resolve(
|
(flow.container as MedusaContainer).resolve(
|
||||||
@@ -541,7 +541,7 @@ function attachOnFinishReleaseEvents(
|
|||||||
{ allowUnregistered: true }
|
{ allowUnregistered: true }
|
||||||
)
|
)
|
||||||
|
|
||||||
if (!eventBusService || !eventGroupId) {
|
if (!eventBusService || !flowEventGroupId) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -549,17 +549,17 @@ function attachOnFinishReleaseEvents(
|
|||||||
|
|
||||||
if (failedStatus.includes(transaction.getState())) {
|
if (failedStatus.includes(transaction.getState())) {
|
||||||
return await eventBusService
|
return await eventBusService
|
||||||
.clearGroupedEvents(eventGroupId)
|
.clearGroupedEvents(flowEventGroupId)
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
logger.warn(
|
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(
|
logger.error(
|
||||||
`Failed to release grouped events for eventGroupId: ${eventGroupId}`,
|
`Failed to release grouped events for eventGroupId: ${flowEventGroupId}`,
|
||||||
e
|
e
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user