@cap-js-community/event-queue 0.1.58 → 0.2.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/README.md +1 -1
- package/db/Event.cds +1 -0
- package/package.json +5 -4
- package/src/EventQueueError.js +15 -0
- package/src/EventQueueProcessorBase.js +136 -105
- package/src/config.js +77 -51
- package/src/dbHandler.js +11 -2
- package/src/initialize.js +27 -26
- package/src/processEventQueue.js +4 -2
- package/src/publishEvent.js +27 -1
- package/src/redisPubSub.js +15 -27
- package/src/runner.js +23 -1
- package/src/shared/EventScheduler.js +53 -0
- package/src/shared/common.js +12 -1
- package/src/shared/redis.js +23 -2
package/src/shared/redis.js
CHANGED
|
@@ -29,9 +29,18 @@ const _createClientBase = () => {
|
|
|
29
29
|
if (env.isOnCF) {
|
|
30
30
|
try {
|
|
31
31
|
const credentials = env.getRedisCredentialsFromEnv();
|
|
32
|
-
|
|
33
|
-
// https://github.com/go-redis/redis/issues/1343
|
|
32
|
+
const redisIsCluster = credentials.cluster_mode;
|
|
34
33
|
const url = credentials.uri.replace(/(?<=rediss:\/\/)[\w-]+?(?=:)/, "");
|
|
34
|
+
if (redisIsCluster) {
|
|
35
|
+
return redis.createCluster({
|
|
36
|
+
rootNodes: [{ url }],
|
|
37
|
+
// https://github.com/redis/node-redis/issues/1782
|
|
38
|
+
defaults: {
|
|
39
|
+
password: credentials.password,
|
|
40
|
+
socket: { tls: credentials.tls },
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
}
|
|
35
44
|
return redis.createClient({ url });
|
|
36
45
|
} catch (err) {
|
|
37
46
|
throw EventQueueError.redisConnectionFailure(err);
|
|
@@ -87,9 +96,21 @@ const publishMessage = async (channel, message) => {
|
|
|
87
96
|
|
|
88
97
|
const _localReconnectStrategy = () => EventQueueError.redisNoReconnect();
|
|
89
98
|
|
|
99
|
+
const closeMainClient = async () => {
|
|
100
|
+
try {
|
|
101
|
+
const client = await mainClientPromise;
|
|
102
|
+
if (client?.quit) {
|
|
103
|
+
await client.quit();
|
|
104
|
+
}
|
|
105
|
+
} catch (err) {
|
|
106
|
+
// ignore errors during shutdown
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
|
|
90
110
|
module.exports = {
|
|
91
111
|
createClientAndConnect,
|
|
92
112
|
createMainClientAndConnect,
|
|
93
113
|
subscribeRedisChannel,
|
|
94
114
|
publishMessage,
|
|
115
|
+
closeMainClient,
|
|
95
116
|
};
|