@cap-js-community/event-queue 2.0.0 → 2.0.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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cap-js-community/event-queue",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.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",
|
|
@@ -1031,7 +1031,7 @@ class EventQueueProcessorBase {
|
|
|
1031
1031
|
const lockAcquired = await distributedLock.acquireLock(
|
|
1032
1032
|
this.__context,
|
|
1033
1033
|
[this.#namespace, this.#eventType, this.#eventSubType].join("##"),
|
|
1034
|
-
{ keepTrackOfLock: true, expiryTime: this.#eventConfig.keepAliveMaxInProgressTime * 1000 }
|
|
1034
|
+
{ keepTrackOfLock: true, expiryTime: this.#eventConfig.keepAliveMaxInProgressTime * 1000, skipNamespace: true }
|
|
1035
1035
|
);
|
|
1036
1036
|
if (!lockAcquired) {
|
|
1037
1037
|
this.logger.debug("no lock available, exit processing", {
|
|
@@ -1074,7 +1074,8 @@ class EventQueueProcessorBase {
|
|
|
1074
1074
|
await trace(this.baseContext, "release-lock", async () => {
|
|
1075
1075
|
await distributedLock.releaseLock(
|
|
1076
1076
|
this.context,
|
|
1077
|
-
[this.#namespace, this.#eventType, this.#eventSubType].join("##")
|
|
1077
|
+
[this.#namespace, this.#eventType, this.#eventSubType].join("##"),
|
|
1078
|
+
{ skipNamespace: true }
|
|
1078
1079
|
);
|
|
1079
1080
|
});
|
|
1080
1081
|
} catch (err) {
|
package/src/runner/runner.js
CHANGED
|
@@ -180,7 +180,7 @@ const _executeEventsAllTenantsRedis = async (tenantIds) => {
|
|
|
180
180
|
}
|
|
181
181
|
};
|
|
182
182
|
|
|
183
|
-
const _executeEventsAllTenants = async (tenantIds
|
|
183
|
+
const _executeEventsAllTenants = async (tenantIds) => {
|
|
184
184
|
const promises = [];
|
|
185
185
|
for (const tenantId of tenantIds) {
|
|
186
186
|
const id = cds.utils.uuid();
|
|
@@ -230,13 +230,6 @@ const _executeEventsAllTenants = async (tenantIds, runId) => {
|
|
|
230
230
|
label,
|
|
231
231
|
async () => {
|
|
232
232
|
try {
|
|
233
|
-
const lockId = `${runId}_${label}`;
|
|
234
|
-
const couldAcquireLock = await distributedLock.acquireLock(context, lockId, {
|
|
235
|
-
expiryTime: eventQueueConfig.runInterval * 0.95,
|
|
236
|
-
});
|
|
237
|
-
if (!couldAcquireLock) {
|
|
238
|
-
return;
|
|
239
|
-
}
|
|
240
233
|
await runEventCombinationForTenant(
|
|
241
234
|
context,
|
|
242
235
|
eventConfig.type,
|
|
@@ -308,50 +301,40 @@ const _singleTenantDb = async () => {
|
|
|
308
301
|
{ newRootSpan: true }
|
|
309
302
|
);
|
|
310
303
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
async () => {
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
return;
|
|
304
|
+
for (const openEvent of events) {
|
|
305
|
+
const eventConfig = config.getEventConfig(openEvent.type, openEvent.subType, openEvent.namespace);
|
|
306
|
+
const label = [openEvent.namespace, eventConfig.type, eventConfig.subType].join("##");
|
|
307
|
+
await WorkerQueue.instance.addToQueue(
|
|
308
|
+
eventConfig.load,
|
|
309
|
+
label,
|
|
310
|
+
eventConfig.priority,
|
|
311
|
+
eventConfig.increasePriorityOverTime,
|
|
312
|
+
async () => {
|
|
313
|
+
return await cds.tx({}, async ({ context }) => {
|
|
314
|
+
await trace(
|
|
315
|
+
context,
|
|
316
|
+
label,
|
|
317
|
+
async () => {
|
|
318
|
+
try {
|
|
319
|
+
await runEventCombinationForTenant(
|
|
320
|
+
context,
|
|
321
|
+
eventConfig.type,
|
|
322
|
+
eventConfig.subType,
|
|
323
|
+
openEvent.namespace,
|
|
324
|
+
{
|
|
325
|
+
skipWorkerPool: true,
|
|
334
326
|
}
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
}
|
|
347
|
-
},
|
|
348
|
-
{ newRootSpan: true }
|
|
349
|
-
);
|
|
350
|
-
});
|
|
351
|
-
}
|
|
352
|
-
);
|
|
353
|
-
})
|
|
354
|
-
);
|
|
327
|
+
);
|
|
328
|
+
} catch (err) {
|
|
329
|
+
cds.log(COMPONENT_NAME).error("executing event-queue run for tenant failed");
|
|
330
|
+
}
|
|
331
|
+
},
|
|
332
|
+
{ newRootSpan: true }
|
|
333
|
+
);
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
);
|
|
337
|
+
}
|
|
355
338
|
};
|
|
356
339
|
|
|
357
340
|
const _singleTenantRedis = async () => {
|
|
@@ -467,7 +450,7 @@ const _multiTenancyDb = async () => {
|
|
|
467
450
|
logger.info("executing event queue run for single instance and multi tenant");
|
|
468
451
|
const tenantIds = await cdsHelper.getAllTenantIds();
|
|
469
452
|
await _checkPeriodicEventUpdate(tenantIds);
|
|
470
|
-
return await _executeEventsAllTenants(tenantIds
|
|
453
|
+
return await _executeEventsAllTenants(tenantIds);
|
|
471
454
|
} catch (err) {
|
|
472
455
|
logger.error("Couldn't fetch tenant ids for event queue processing! Next try after defined interval.", err);
|
|
473
456
|
}
|
|
@@ -11,9 +11,9 @@ const COMPONENT_NAME = "/eventQueue/distributedLock";
|
|
|
11
11
|
const acquireLock = async (
|
|
12
12
|
context,
|
|
13
13
|
key,
|
|
14
|
-
{ tenantScoped = true, expiryTime = config.globalTxTimeout, keepTrackOfLock = false } = {}
|
|
14
|
+
{ tenantScoped = true, expiryTime = config.globalTxTimeout, keepTrackOfLock = false, skipNamespace = false } = {}
|
|
15
15
|
) => {
|
|
16
|
-
const fullKey = _generateKey(context, tenantScoped, key);
|
|
16
|
+
const fullKey = _generateKey(context, tenantScoped, key, skipNamespace);
|
|
17
17
|
if (config.redisEnabled) {
|
|
18
18
|
return await _acquireLockRedis(context, fullKey, expiryTime, { keepTrackOfLock });
|
|
19
19
|
} else {
|
|
@@ -51,8 +51,8 @@ const setValueWithExpire = async (
|
|
|
51
51
|
}
|
|
52
52
|
};
|
|
53
53
|
|
|
54
|
-
const releaseLock = async (context, key, { tenantScoped = true } = {}) => {
|
|
55
|
-
const fullKey = _generateKey(context, tenantScoped, key);
|
|
54
|
+
const releaseLock = async (context, key, { tenantScoped = true, skipNamespace = false } = {}) => {
|
|
55
|
+
const fullKey = _generateKey(context, tenantScoped, key, skipNamespace);
|
|
56
56
|
if (config.redisEnabled) {
|
|
57
57
|
return await _releaseLockRedis(context, fullKey);
|
|
58
58
|
} else {
|
|
@@ -194,8 +194,8 @@ const _acquireLockDB = async (
|
|
|
194
194
|
return result;
|
|
195
195
|
};
|
|
196
196
|
|
|
197
|
-
const _generateKey = (context, tenantScoped, key) => {
|
|
198
|
-
const keyParts = [config.redisNamespace()];
|
|
197
|
+
const _generateKey = (context, tenantScoped, key, skipNamespace) => {
|
|
198
|
+
const keyParts = [config.redisNamespace(!skipNamespace)];
|
|
199
199
|
tenantScoped && keyParts.push(context.tenant);
|
|
200
200
|
keyParts.push(key);
|
|
201
201
|
return `${keyParts.join("##")}`;
|