@cap-js-community/event-queue 1.9.0-beta.1 → 1.9.0-beta.2
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.9.0-beta.
|
|
3
|
+
"version": "1.9.0-beta.2",
|
|
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",
|
|
@@ -852,7 +852,7 @@ class EventQueueProcessorBase {
|
|
|
852
852
|
// eslint-disable-next-line no-unused-vars
|
|
853
853
|
async beforeProcessingEvents() {}
|
|
854
854
|
|
|
855
|
-
async
|
|
855
|
+
async isOutdatedAndKeepAlive() {
|
|
856
856
|
if (this.__keepAliveViolated) {
|
|
857
857
|
return true;
|
|
858
858
|
}
|
package/src/processEventQueue.js
CHANGED
|
@@ -159,6 +159,7 @@ const processPeriodicEvent = async (context, eventTypeInstance) => {
|
|
|
159
159
|
`eventQueue-periodic-process-${eventTypeInstance.eventType}##${eventTypeInstance.eventSubType}`,
|
|
160
160
|
async (tx) => {
|
|
161
161
|
await trace(eventTypeInstance.context, "process-periodic-event", async () => {
|
|
162
|
+
eventTypeInstance.continuesKeepAlive();
|
|
162
163
|
eventTypeInstance.processEventContext = tx.context;
|
|
163
164
|
eventTypeInstance.setTxForEventProcessing(queueEntry.ID, cds.tx(tx.context));
|
|
164
165
|
try {
|
|
@@ -170,6 +171,7 @@ const processPeriodicEvent = async (context, eventTypeInstance) => {
|
|
|
170
171
|
await tx.rollback();
|
|
171
172
|
return;
|
|
172
173
|
} finally {
|
|
174
|
+
eventTypeInstance.stopKeepAlive();
|
|
173
175
|
eventTypeInstance.endPerformanceTracerPeriodicEvents();
|
|
174
176
|
}
|
|
175
177
|
if (
|
|
@@ -198,6 +200,8 @@ const processPeriodicEvent = async (context, eventTypeInstance) => {
|
|
|
198
200
|
eventType: eventTypeInstance?.eventType,
|
|
199
201
|
eventSubType: eventTypeInstance?.eventSubType,
|
|
200
202
|
});
|
|
203
|
+
} finally {
|
|
204
|
+
await eventTypeInstance.keepAlivePromise;
|
|
201
205
|
}
|
|
202
206
|
};
|
|
203
207
|
|
|
@@ -314,7 +318,7 @@ const _checkEventIsBlocked = async (baseInstance) => {
|
|
|
314
318
|
|
|
315
319
|
const _processEvent = async (eventTypeInstance, processContext, key, queueEntries, payload) => {
|
|
316
320
|
try {
|
|
317
|
-
const eventOutdated = await eventTypeInstance.
|
|
321
|
+
const eventOutdated = await eventTypeInstance.isOutdatedAndKeepAlive(queueEntries);
|
|
318
322
|
if (eventOutdated) {
|
|
319
323
|
// NOTE: return empty status map to comply with the interface
|
|
320
324
|
return {};
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const cds = require("@sap/cds");
|
|
4
|
-
let otel
|
|
4
|
+
let otel;
|
|
5
5
|
try {
|
|
6
|
-
telemetry = require("@cap-js/telemetry");
|
|
7
6
|
otel = require("@opentelemetry/api");
|
|
8
7
|
} catch {
|
|
9
8
|
// ignore
|
|
@@ -14,12 +13,13 @@ const config = require("../config");
|
|
|
14
13
|
const COMPONENT_NAME = "/shared/openTelemetry";
|
|
15
14
|
|
|
16
15
|
const trace = async (context, label, fn, { attributes = {}, newRootSpan = false } = {}) => {
|
|
17
|
-
|
|
16
|
+
const tracerProvider = otel?.trace.getTracerProvider();
|
|
17
|
+
// Check if a real provider is registered
|
|
18
|
+
if (!config.enableCAPTelemetry || !tracerProvider || tracerProvider === otel.trace.NOOP_TRACER_PROVIDER) {
|
|
18
19
|
return fn();
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
const tracer = otel.trace.getTracer("eventqueue");
|
|
22
|
-
|
|
23
23
|
const span = tracer.startSpan(`eventqueue-${label}`, {
|
|
24
24
|
kind: otel.SpanKind.INTERNAL,
|
|
25
25
|
root: newRootSpan,
|