cap-js-community / event-queue

An event queue that enables secure multi-tenant enabled transactional processing of asynchronous events, featuring instant event processing with Redis Pub/Sub and load distribution across all application instances.
https://cap-js-community.github.io/event-queue/
Apache License 2.0
11 stars 1 forks source link

[Feature Request] Disable event collector in before commit event #193

Closed Phantomkeks closed 2 weeks ago

Phantomkeks commented 3 weeks ago

With version 1.4.4 the following code was introduced: https://github.com/cap-js-community/event-queue/blob/2b54288e66498d6c3d6ea8c99d8da4f9c1a2acd8/src/publishEvent.js#L67

tx.context.before("commit", async () => {
    if (!tx._eventQueue.events?.length) {
      return;
    }
    await tx.run(INSERT.into(config.tableNameEventQueue).entries(tx._eventQueue.events));
    tx._eventQueue = null;
  });

Would be nice to disable this collection of events of the transaction context. Because I experienced an issue, when using the following coding (CAP + EventQueue):

db.before("COMMIT", async (req) => {
   ... 
   eventQueue.publishEvent(tx, events);
}):

As a consequence of the parallel handling of the before commit handlers, the event queue events are not inserted in the database and therefore lost.

My suggestion would be a disable flag in the publishEvent function.

soccermax commented 2 weeks ago

fixed by https://github.com/cap-js-community/event-queue/pull/196