@cap-js-community/event-queue 1.5.0 → 1.5.1
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 +1 -1
- package/src/dbHandler.js +3 -3
- package/src/shared/eventScheduler.js +6 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cap-js-community/event-queue",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.1",
|
|
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
|
|
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.
|
|
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,
|
|
@@ -28,7 +28,8 @@ class EventScheduler {
|
|
|
28
28
|
delaySeconds: (date.getTime() - Date.now()) / 1000,
|
|
29
29
|
});
|
|
30
30
|
this.#eventsByTenants[tenantId] ??= {};
|
|
31
|
-
|
|
31
|
+
let timeoutId;
|
|
32
|
+
const timeout = setTimeout(() => {
|
|
32
33
|
delete this.#eventsByTenants[tenantId][timeoutId];
|
|
33
34
|
delete this.#scheduledEvents[key];
|
|
34
35
|
redisPub.broadcastEvent(tenantId, { type, subType }).catch((err) => {
|
|
@@ -40,6 +41,10 @@ class EventScheduler {
|
|
|
40
41
|
});
|
|
41
42
|
});
|
|
42
43
|
}, relative).unref();
|
|
44
|
+
// Convert the timeout object to a primitive timeout id to avoid circular dependencies between the callback of setTimeout
|
|
45
|
+
// and the closure. The usage of the timeout object in the callback, leads to a deadlock for the garbage collector
|
|
46
|
+
// as the timeout object has a reference to the callback of setTimeout.
|
|
47
|
+
timeoutId = String(timeout);
|
|
43
48
|
this.#eventsByTenants[tenantId][timeoutId] = true;
|
|
44
49
|
}
|
|
45
50
|
|