@cap-js-community/event-queue 1.3.4 → 1.3.5
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 +6 -1
- package/src/redisPubSub.js +29 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cap-js-community/event-queue",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.5",
|
|
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
|
"files": [
|
|
@@ -70,6 +70,11 @@
|
|
|
70
70
|
"eventQueue": {
|
|
71
71
|
"[production]": {
|
|
72
72
|
"disableRedis": false
|
|
73
|
+
},
|
|
74
|
+
"[test]": {
|
|
75
|
+
"registerAsEventProcessor": false,
|
|
76
|
+
"isRunnerDeactivated": true,
|
|
77
|
+
"updatePeriodicEvents": false
|
|
73
78
|
}
|
|
74
79
|
},
|
|
75
80
|
"requires": {
|
package/src/redisPubSub.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
const { promisify } = require("util");
|
|
4
|
+
|
|
3
5
|
const cds = require("@sap/cds");
|
|
4
6
|
|
|
5
7
|
const redis = require("./shared/redis");
|
|
@@ -10,7 +12,10 @@ const { getSubdomainForTenantId } = require("./shared/cdsHelper");
|
|
|
10
12
|
|
|
11
13
|
const EVENT_MESSAGE_CHANNEL = "EVENT_QUEUE_MESSAGE_CHANNEL";
|
|
12
14
|
const COMPONENT_NAME = "/eventQueue/redisPubSub";
|
|
15
|
+
const TRIES_FOR_PUBLISH_PERIODIC_EVENT = 10;
|
|
16
|
+
const SLEEP_TIME_FOR_PUBLISH_PERIODIC_EVENT = 30 * 1000;
|
|
13
17
|
|
|
18
|
+
const wait = promisify(setTimeout);
|
|
14
19
|
let subscriberClientPromise;
|
|
15
20
|
|
|
16
21
|
const initEventQueueRedisSubscribe = () => {
|
|
@@ -107,23 +112,34 @@ const broadcastEvent = async (tenantId, type, subType) => {
|
|
|
107
112
|
}
|
|
108
113
|
return;
|
|
109
114
|
}
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
115
|
+
const eventConfig = config.getEventConfig(type, subType);
|
|
116
|
+
for (let i = 0; i < TRIES_FOR_PUBLISH_PERIODIC_EVENT; i++) {
|
|
117
|
+
const result = await checkLockExistsAndReturnValue(
|
|
118
|
+
new cds.EventContext({ tenant: tenantId }),
|
|
119
|
+
[type, subType].join("##")
|
|
120
|
+
);
|
|
121
|
+
if (result) {
|
|
122
|
+
logger.debug("skip publish redis event as no lock is available", {
|
|
123
|
+
type,
|
|
124
|
+
subType,
|
|
125
|
+
index: i,
|
|
126
|
+
isPeriodic: eventConfig.isPeriodic,
|
|
127
|
+
waitInterval: SLEEP_TIME_FOR_PUBLISH_PERIODIC_EVENT,
|
|
128
|
+
});
|
|
129
|
+
if (!eventConfig.isPeriodic) {
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
await wait(SLEEP_TIME_FOR_PUBLISH_PERIODIC_EVENT);
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
logger.debug("publishing redis event", {
|
|
136
|
+
tenantId,
|
|
116
137
|
type,
|
|
117
138
|
subType,
|
|
118
139
|
});
|
|
119
|
-
|
|
140
|
+
await redis.publishMessage(EVENT_MESSAGE_CHANNEL, JSON.stringify({ tenantId, type, subType }));
|
|
141
|
+
break;
|
|
120
142
|
}
|
|
121
|
-
logger.debug("publishing redis event", {
|
|
122
|
-
tenantId,
|
|
123
|
-
type,
|
|
124
|
-
subType,
|
|
125
|
-
});
|
|
126
|
-
await redis.publishMessage(EVENT_MESSAGE_CHANNEL, JSON.stringify({ tenantId, type, subType }));
|
|
127
143
|
} catch (err) {
|
|
128
144
|
logger.error("publish event failed!", err, {
|
|
129
145
|
tenantId,
|