@cap-js-community/event-queue 0.1.51 → 0.1.53

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": "0.1.51",
3
+ "version": "0.1.53",
4
4
  "description": "event queue for cds",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -43,7 +43,7 @@
43
43
  "eslint-plugin-node": "11.1.0",
44
44
  "sqlite3": "5.1.6",
45
45
  "express": "4.18.2",
46
- "@sap/cds": "7.0.0",
46
+ "@sap/cds": "7.1.0",
47
47
  "eslint": "^8.39.0",
48
48
  "eslint-config-prettier": "^8.8.0",
49
49
  "eslint-plugin-jest": "^27.2.1",
@@ -702,7 +702,7 @@ class EventQueueProcessorBase {
702
702
  } else if (runningChecks.length) {
703
703
  await Promise.allSettled(runningChecks);
704
704
  }
705
- const checkAndUpdatePromise = new Promise((resolve) => {
705
+ const checkAndUpdatePromise = new Promise((resolve, reject) => {
706
706
  executeInNewTransaction(this.__baseContext, "eventProcessing-isOutdatedAndKeepalive", async (tx) => {
707
707
  const queueEntriesFresh = await tx.run(
708
708
  SELECT.from(this.__eventQueueConfig.tableNameEventQueue)
@@ -747,7 +747,7 @@ class EventQueueProcessorBase {
747
747
  delete this.__keepalivePromises[queueEntryFresh.ID];
748
748
  });
749
749
  resolve(eventOutdated);
750
- });
750
+ }).catch(reject);
751
751
  });
752
752
 
753
753
  queueEntries.forEach((queueEntry) => (this.__keepalivePromises[queueEntry.ID] = checkAndUpdatePromise));
@@ -2,6 +2,8 @@
2
2
 
3
3
  const COMPONENT = "eventQueue/SetIntervalDriftSafe";
4
4
 
5
+ const ALLOWED_SHIFT_IN_PROCENT = 0.1;
6
+
5
7
  class SetIntervalDriftSafe {
6
8
  #adjustedInterval;
7
9
  #interval;
@@ -19,8 +21,11 @@ class SetIntervalDriftSafe {
19
21
  const now = Date.now();
20
22
  if (this.#expectedCycleTime === 0) {
21
23
  this.#expectedCycleTime = now + this.#interval;
22
- } else if (now + this.#interval - this.#nextTickScheduledFor < this.#interval) {
23
- this.#logger.info("overlapping ticks, skipping this run");
24
+ } else if (
25
+ Math.abs(now + this.#interval - this.#nextTickScheduledFor - this.#interval) >
26
+ this.#interval * ALLOWED_SHIFT_IN_PROCENT
27
+ ) {
28
+ this.#logger.log("overlapping ticks, skipping this run");
24
29
  return;
25
30
  } else {
26
31
  this.#adjustedInterval = this.#interval - (now - this.#expectedCycleTime);