@cap-js-community/event-queue 1.6.2 → 1.6.3
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.6.
|
|
3
|
+
"version": "1.6.3",
|
|
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",
|
|
@@ -384,38 +384,46 @@ class EventQueueProcessorBase {
|
|
|
384
384
|
* The function accepts no arguments as there are dedicated functions to set the status of events (e.g. setEventStatus)
|
|
385
385
|
*/
|
|
386
386
|
async persistEventStatus(tx, { skipChecks, statusMap = this.__statusMap } = {}) {
|
|
387
|
-
|
|
388
|
-
this
|
|
387
|
+
this.logger.debug("entering persistEventStatus", {
|
|
388
|
+
eventType: this.#eventType,
|
|
389
|
+
eventSubType: this.#eventSubType,
|
|
390
|
+
});
|
|
391
|
+
this.#ensureOnlySelectedQueueEntries(statusMap);
|
|
392
|
+
if (!skipChecks) {
|
|
393
|
+
this.#ensureEveryQueueEntryHasStatus();
|
|
394
|
+
}
|
|
395
|
+
this.#ensureEveryStatusIsAllowed(statusMap);
|
|
396
|
+
|
|
397
|
+
const { success, failed, exceeded, invalidAttempts } = Object.entries(statusMap).reduce(
|
|
398
|
+
(result, [notificationEntityId, processingStatus]) => {
|
|
399
|
+
this.__commitedStatusMap[notificationEntityId] = processingStatus;
|
|
400
|
+
if (processingStatus === EventProcessingStatus.Open) {
|
|
401
|
+
result.invalidAttempts.push(notificationEntityId);
|
|
402
|
+
} else if (processingStatus === EventProcessingStatus.Done) {
|
|
403
|
+
result.success.push(notificationEntityId);
|
|
404
|
+
} else if (processingStatus === EventProcessingStatus.Error) {
|
|
405
|
+
result.failed.push(notificationEntityId);
|
|
406
|
+
} else if (processingStatus === EventProcessingStatus.Exceeded) {
|
|
407
|
+
result.exceeded.push(notificationEntityId);
|
|
408
|
+
}
|
|
409
|
+
return result;
|
|
410
|
+
},
|
|
411
|
+
{
|
|
412
|
+
success: [],
|
|
413
|
+
failed: [],
|
|
414
|
+
exceeded: [],
|
|
415
|
+
invalidAttempts: [],
|
|
416
|
+
}
|
|
417
|
+
);
|
|
418
|
+
if (![success, failed, exceeded, invalidAttempts].some((statusArray) => statusArray.length)) {
|
|
419
|
+
this.logger.debug("exiting persistEventStatus", {
|
|
389
420
|
eventType: this.#eventType,
|
|
390
421
|
eventSubType: this.#eventSubType,
|
|
391
422
|
});
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
this.#ensureEveryStatusIsAllowed(statusMap);
|
|
397
|
-
|
|
398
|
-
const { success, failed, exceeded, invalidAttempts } = Object.entries(statusMap).reduce(
|
|
399
|
-
(result, [notificationEntityId, processingStatus]) => {
|
|
400
|
-
this.__commitedStatusMap[notificationEntityId] = processingStatus;
|
|
401
|
-
if (processingStatus === EventProcessingStatus.Open) {
|
|
402
|
-
result.invalidAttempts.push(notificationEntityId);
|
|
403
|
-
} else if (processingStatus === EventProcessingStatus.Done) {
|
|
404
|
-
result.success.push(notificationEntityId);
|
|
405
|
-
} else if (processingStatus === EventProcessingStatus.Error) {
|
|
406
|
-
result.failed.push(notificationEntityId);
|
|
407
|
-
} else if (processingStatus === EventProcessingStatus.Exceeded) {
|
|
408
|
-
result.exceeded.push(notificationEntityId);
|
|
409
|
-
}
|
|
410
|
-
return result;
|
|
411
|
-
},
|
|
412
|
-
{
|
|
413
|
-
success: [],
|
|
414
|
-
failed: [],
|
|
415
|
-
exceeded: [],
|
|
416
|
-
invalidAttempts: [],
|
|
417
|
-
}
|
|
418
|
-
);
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
return await trace(this.baseContext, "persist-event-status", async () => {
|
|
419
427
|
this.logger.debug("persistEventStatus for entries", {
|
|
420
428
|
eventType: this.#eventType,
|
|
421
429
|
eventSubType: this.#eventSubType,
|
|
@@ -455,10 +463,6 @@ class EventQueueProcessorBase {
|
|
|
455
463
|
.where("ID IN", eventIds)
|
|
456
464
|
);
|
|
457
465
|
}
|
|
458
|
-
this.logger.debug("exiting persistEventStatus", {
|
|
459
|
-
eventType: this.#eventType,
|
|
460
|
-
eventSubType: this.#eventSubType,
|
|
461
|
-
});
|
|
462
466
|
});
|
|
463
467
|
}
|
|
464
468
|
|
|
@@ -10,6 +10,8 @@ try {
|
|
|
10
10
|
|
|
11
11
|
const config = require("../config");
|
|
12
12
|
|
|
13
|
+
const COMPONENT_NAME = "/shared/openTelemetry";
|
|
14
|
+
|
|
13
15
|
const trace = async (context, label, fn, { attributes = {}, newRootSpan = false } = {}) => {
|
|
14
16
|
if (!config.enableCAPTelemetry || !otel || !cds._telemetry?.tracer) {
|
|
15
17
|
return fn();
|
|
@@ -34,8 +36,14 @@ const trace = async (context, label, fn, { attributes = {}, newRootSpan = false
|
|
|
34
36
|
throw e;
|
|
35
37
|
};
|
|
36
38
|
const onDone = () => {
|
|
37
|
-
|
|
38
|
-
span.
|
|
39
|
+
try {
|
|
40
|
+
if (span.status?.code !== otel.SpanStatusCode.UNSET && !span.ended) {
|
|
41
|
+
span.end?.();
|
|
42
|
+
}
|
|
43
|
+
} catch (err) {
|
|
44
|
+
cds.log(COMPONENT_NAME).error("error in tracing", err, {
|
|
45
|
+
span,
|
|
46
|
+
});
|
|
39
47
|
}
|
|
40
48
|
};
|
|
41
49
|
|