@cap-js-community/event-queue 1.2.2 → 1.2.4

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,7 +1,7 @@
1
1
  {
2
2
  "name": "@cap-js-community/event-queue",
3
- "version": "1.2.2",
4
- "description": "An event queue that enables secure transactional processing of asynchronous events, featuring instant event processing with Redis Pub/Sub and load distribution across all application instances.",
3
+ "version": "1.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
  "files": [
7
7
  "src",
@@ -42,7 +42,7 @@
42
42
  "node": ">=18"
43
43
  },
44
44
  "dependencies": {
45
- "redis": "4.6.12",
45
+ "redis": "4.6.13",
46
46
  "verror": "1.10.1",
47
47
  "yaml": "2.3.4"
48
48
  },
@@ -21,6 +21,8 @@ const SELECT_LIMIT_EVENTS_PER_TICK = 100;
21
21
  const TRIES_FOR_EXCEEDED_EVENTS = 3;
22
22
  const EVENT_START_AFTER_HEADROOM = 3 * 1000;
23
23
 
24
+ let serviceBindingCache = null;
25
+
24
26
  class EventQueueProcessorBase {
25
27
  #eventsWithExceededTries = [];
26
28
  #exceededTriesExceeded = [];
@@ -673,16 +675,14 @@ class EventQueueProcessorBase {
673
675
  });
674
676
  let txSchema, serviceManagerSchema;
675
677
  try {
676
- const mtxServiceManager = require("@sap/cds-mtxs/srv/plugins/hana/srv-mgr");
677
678
  const schemaPromise = tx.run("SELECT CURRENT_SCHEMA FROM DUMMY");
678
- const serviceManagerBindingsPromise = mtxServiceManager.getAll();
679
- const [schema, serviceManagerBindings] = await Promise.allSettled([schemaPromise, serviceManagerBindingsPromise]);
679
+ const [schema, serviceManagerBindings] = await Promise.allSettled([schemaPromise, this.#getServiceBindings()]);
680
680
  if (schema.reason) {
681
681
  errorHandler(schema.reason);
682
682
  return;
683
683
  }
684
684
  if (serviceManagerBindings.reason) {
685
- errorHandler(schema.reason);
685
+ errorHandler(serviceManagerBindings.reason);
686
686
  return;
687
687
  }
688
688
 
@@ -699,6 +699,19 @@ class EventQueueProcessorBase {
699
699
  }
700
700
  }
701
701
 
702
+ async #getServiceBindings() {
703
+ if (!(serviceBindingCache && serviceBindingCache.expireTs >= Date.now())) {
704
+ const mtxServiceManager = require("@sap/cds-mtxs/srv/plugins/hana/srv-mgr");
705
+ serviceBindingCache = {
706
+ expireTs: Date.now() + 10 * 60 * 1000,
707
+ value: mtxServiceManager.getAll().catch(() => {
708
+ serviceBindingCache = null;
709
+ }),
710
+ };
711
+ }
712
+ return await serviceBindingCache.value;
713
+ }
714
+
702
715
  async #selectLastSuccessfulPeriodicTimestamp() {
703
716
  const entry = await SELECT.one
704
717
  .from(this.#config.tableNameEventQueue)