fix(): Event group id propagation and event managements (#12157)

This commit is contained in:
Adrien de Peretti
2025-04-14 20:57:52 +02:00
committed by GitHub
parent 3a481290ea
commit 2f6963a5fb
22 changed files with 777 additions and 592 deletions

View File

@@ -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