feat(core, event-bus): Compensate emit event step utility (#13281)

* feat(core, event-bus): Compensate emit event step utility

* tests

* Update changeset to remove integration-tests-modules

Removed integration-tests-modules from changeset.

* revert test script
This commit is contained in:
Adrien de Peretti
2025-08-25 15:08:09 +02:00
committed by GitHub
parent 73a25abecb
commit fc49253273
11 changed files with 547 additions and 22 deletions
@@ -218,11 +218,49 @@ export default class RedisEventBusService extends AbstractEventBusModuleService
await this.clearGroupedEvents(eventGroupId)
}
async clearGroupedEvents(eventGroupId: string) {
async clearGroupedEvents(
eventGroupId: string,
{
eventNames,
}: {
eventNames?: string[]
} = {}
) {
if (!eventGroupId) {
return
}
if (eventNames?.length) {
/**
* If any event names are provided, we keep all events except the ones that match the event
* names. which allow to partially clear an event group.
*/
const eventsToKeep = await this.eventBusRedisConnection_
.lrange(`staging:${eventGroupId}`, 0, -1)
.then((result) => {
return result
.map((jsonString) => JSON.parse(jsonString))
.filter((event) => !eventNames.includes(event.name))
})
// Create a pipeline
const pipeline = this.eventBusRedisConnection_.pipeline()
// Empty the current list
pipeline.del(`staging:${eventGroupId}`)
// Add the remaining events to the list
pipeline.rpush(
`staging:${eventGroupId}`,
...eventsToKeep.map((event) => JSON.stringify(event))
)
await pipeline.exec()
return
}
await this.eventBusRedisConnection_.unlink(`staging:${eventGroupId}`)
}