fix(): Event group id propagation and event managements (#12157)
This commit is contained in:
@@ -82,13 +82,14 @@ export default class LocalEventBusService extends AbstractEventBusModuleService
|
||||
// This is useful in the event of a distributed transaction where you'd want to emit
|
||||
// events only once the transaction ends.
|
||||
private async groupOrEmitEvent<T = unknown>(eventData: Message<T>) {
|
||||
const { options, ...eventBody } = eventData
|
||||
const eventData_ = JSON.parse(JSON.stringify(eventData))
|
||||
const { options, ...eventBody } = eventData_
|
||||
const eventGroupId = eventBody.metadata?.eventGroupId
|
||||
|
||||
if (eventGroupId) {
|
||||
await this.groupEvent(eventGroupId, eventData)
|
||||
await this.groupEvent(eventGroupId, eventData_)
|
||||
} else {
|
||||
const { options, ...eventBody } = eventData
|
||||
const { options, ...eventBody } = eventData_
|
||||
|
||||
const options_ = options as { delay: number }
|
||||
const delay = (ms?: number) => (ms ? setTimeout(ms) : Promise.resolve())
|
||||
@@ -112,7 +113,8 @@ export default class LocalEventBusService extends AbstractEventBusModuleService
|
||||
}
|
||||
|
||||
async releaseGroupedEvents(eventGroupId: string) {
|
||||
const groupedEvents = this.groupedEventsMap_.get(eventGroupId) || []
|
||||
let groupedEvents = this.groupedEventsMap_.get(eventGroupId) || []
|
||||
groupedEvents = JSON.parse(JSON.stringify(groupedEvents))
|
||||
|
||||
for (const event of groupedEvents) {
|
||||
const { options, ...eventBody } = event
|
||||
|
||||
@@ -686,7 +686,7 @@ export class PostgresProvider implements IndexTypes.StorageProvider {
|
||||
})
|
||||
|
||||
let relationsToUpsert: any[] = []
|
||||
const entitiesToUpdate = cleanedData.map((entityData) => {
|
||||
const entitiesToUpsert = cleanedData.map((entityData) => {
|
||||
relationsToUpsert.push(
|
||||
{
|
||||
parent_id: entityData[parentPropertyId] as string,
|
||||
@@ -714,8 +714,8 @@ export class PostgresProvider implements IndexTypes.StorageProvider {
|
||||
}
|
||||
})
|
||||
|
||||
if (entitiesToUpdate.length) {
|
||||
await indexRepository.upsertMany(entitiesToUpdate, {
|
||||
if (entitiesToUpsert.length) {
|
||||
await indexRepository.upsertMany(entitiesToUpsert, {
|
||||
onConflictAction: "merge",
|
||||
onConflictFields: ["id", "name"],
|
||||
onConflictMergeFields: ["data", "staled_at"],
|
||||
|
||||
@@ -35,8 +35,7 @@ moduleIntegrationTestRunner<IWorkflowEngineService>({
|
||||
},
|
||||
},
|
||||
testSuite: ({ service: workflowOrcModule, medusaApp }) => {
|
||||
// TODO: Debug the issue with this test https://github.com/medusajs/medusa/actions/runs/13900190144/job/38897122803#step:5:5616
|
||||
describe.skip("Testing race condition of the workflow during retry", () => {
|
||||
describe("Testing race condition of the workflow during retry", () => {
|
||||
it("should prevent race continuation of the workflow during retryIntervalAwaiting in background execution", (done) => {
|
||||
const transactionId = "transaction_id"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user