@cap-js-community/event-queue 1.4.6 → 1.4.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cap-js-community/event-queue",
3
- "version": "1.4.6",
3
+ "version": "1.4.7",
4
4
  "description": "An event queue that enables secure transactional processing of asynchronous and periodic events, featuring instant event processing with Redis Pub/Sub and load distribution across all application instances.",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",
package/src/dbHandler.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  const cds = require("@sap/cds");
4
4
 
5
- const { broadcastEvent } = require("./redis/redisPub");
5
+ const redisPub = require("./redis/redisPub");
6
6
  const config = require("./config");
7
7
 
8
8
  const COMPONENT_NAME = "/eventQueue/dbHandler";
@@ -25,7 +25,7 @@ const registerEventQueueDbHandler = (dbService) => {
25
25
  req.tx._ = req.tx._ ?? {};
26
26
  req.tx._.eventQueuePublishEvents = req.tx._.eventQueuePublishEvents ?? {};
27
27
  const eventQueuePublishEvents = req.tx._.eventQueuePublishEvents;
28
- const data = Array.isArray(req.data) ? req.data : [req.data];
28
+ const data = Array.isArray(req.query.INSERT.entries) ? req.query.INSERT.entries : [req.query.INSERT.entries];
29
29
  const eventCombinations = Object.keys(
30
30
  data.reduce((result, event) => {
31
31
  const key = [event.type, event.subType].join("##");
@@ -45,7 +45,7 @@ const registerEventQueueDbHandler = (dbService) => {
45
45
  return { type, subType };
46
46
  });
47
47
 
48
- broadcastEvent(req.tenant, events).catch((err) => {
48
+ redisPub.broadcastEvent(req.tenant, events).catch((err) => {
49
49
  cds.log(COMPONENT_NAME).error("db handler failure during broadcasting event", err, {
50
50
  tenant: req.tenant,
51
51
  events,
@@ -27,9 +27,7 @@ class EventScheduler {
27
27
  subType,
28
28
  delaySeconds: (date.getTime() - Date.now()) / 1000,
29
29
  });
30
- this.#eventsByTenants[tenantId] ??= {};
31
- const timeoutId = setTimeout(() => {
32
- delete this.#eventsByTenants[tenantId][timeoutId];
30
+ setTimeout(() => {
33
31
  delete this.#scheduledEvents[key];
34
32
  redisPub.broadcastEvent(tenantId, { type, subType }).catch((err) => {
35
33
  cds.log(COMPONENT_NAME).error("could not execute scheduled event", err, {
@@ -40,12 +38,9 @@ class EventScheduler {
40
38
  });
41
39
  });
42
40
  }, relative).unref();
43
- this.#eventsByTenants[tenantId][timeoutId] = true;
44
41
  }
45
42
 
46
- clearForTenant(tenantId) {
47
- Object.values(this.#eventsByTenants[tenantId]).forEach((timeoutId) => clearTimeout(timeoutId));
48
- }
43
+ clearForTenant() {}
49
44
 
50
45
  calculateOffset(type, subType, startAfter) {
51
46
  const eventConfig = config.getEventConfig(type, subType);