@cap-js-community/event-queue 1.9.0-beta.0 → 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.0",
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 isOutdatedAndKeepalive() {
855
+ async isOutdatedAndKeepAlive() {
856
856
  if (this.__keepAliveViolated) {
857
857
  return true;
858
858
  }
package/src/config.js CHANGED
@@ -18,7 +18,7 @@ const MIN_INTERVAL_SEC = 10;
18
18
  const DEFAULT_LOAD = 1;
19
19
  const DEFAULT_PRIORITY = Priorities.Medium;
20
20
  const DEFAULT_INCREASE_PRIORITY = true;
21
- const DEFAULT_KEEP_ALIVE_INTERVAL_MIN = 1;
21
+ const DEFAULT_KEEP_ALIVE_INTERVAL = 60;
22
22
  const DEFAULT_MAX_FACTOR_STUCK_2_KEEP_ALIVE_INTERVAL = 3.5;
23
23
  const SUFFIX_PERIODIC = "_PERIODIC";
24
24
  const COMMAND_BLOCK = "EVENT_QUEUE_EVENT_BLOCK";
@@ -386,7 +386,7 @@ class Config {
386
386
  event.load = event.load ?? DEFAULT_LOAD;
387
387
  event.priority = event.priority ?? DEFAULT_PRIORITY;
388
388
  event.increasePriorityOverTime = event.increasePriorityOverTime ?? DEFAULT_INCREASE_PRIORITY;
389
- event.keepAliveInterval = (event.keepAliveInterval ?? DEFAULT_KEEP_ALIVE_INTERVAL_MIN) * 60 * 1000;
389
+ event.keepAliveInterval = (event.keepAliveInterval ?? DEFAULT_KEEP_ALIVE_INTERVAL) * 1000;
390
390
  event.keepAliveMaxInProgressTime = event.keepAliveInterval * DEFAULT_MAX_FACTOR_STUCK_2_KEEP_ALIVE_INTERVAL;
391
391
  }
392
392
 
@@ -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.isOutdatedAndKeepalive(queueEntries);
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 {};
@@ -13,11 +13,14 @@ const config = require("../config");
13
13
  const COMPONENT_NAME = "/shared/openTelemetry";
14
14
 
15
15
  const trace = async (context, label, fn, { attributes = {}, newRootSpan = false } = {}) => {
16
- if (!config.enableCAPTelemetry || !otel || !cds._telemetry?.tracer) {
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) {
17
19
  return fn();
18
20
  }
19
21
 
20
- const span = cds._telemetry.tracer.startSpan(`eventqueue-${label}`, {
22
+ const tracer = otel.trace.getTracer("eventqueue");
23
+ const span = tracer.startSpan(`eventqueue-${label}`, {
21
24
  kind: otel.SpanKind.INTERNAL,
22
25
  root: newRootSpan,
23
26
  });