Skip to content

Commit

Permalink
fix promise handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Gruenfelder committed Feb 7, 2024
1 parent a7c3460 commit 21a2583
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 27 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## v1.2.4 - 2024-02-07

### Changed

- Optimize promise handling

## v1.2.3 - 2024-02-07

### Changed
Expand Down
43 changes: 24 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cap-js-community/event-queue",
"version": "1.2.3",
"version": "1.2.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.",
"main": "src/index.js",
"files": [
Expand Down
17 changes: 10 additions & 7 deletions src/EventQueueProcessorBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const SELECT_LIMIT_EVENTS_PER_TICK = 100;
const TRIES_FOR_EXCEEDED_EVENTS = 3;
const EVENT_START_AFTER_HEADROOM = 3 * 1000;

let serviceBindingCache = {};
let serviceBindingCache = null;

class EventQueueProcessorBase {
#eventsWithExceededTries = [];
Expand Down Expand Up @@ -700,13 +700,16 @@ class EventQueueProcessorBase {
}

async #getServiceBindings() {
if (serviceBindingCache && serviceBindingCache.exipreTs >= Date.now()) {
return serviceBindingCache.value;
if (!(serviceBindingCache && serviceBindingCache.expireTs >= Date.now())) {
const mtxServiceManager = require("@sap/cds-mtxs/srv/plugins/hana/srv-mgr");
serviceBindingCache = {
expireTs: Date.now() + 10 * 60 * 1000,
value: mtxServiceManager.getAll().catch(() => {
serviceBindingCache = null;
}),
};
}
const mtxServiceManager = require("@sap/cds-mtxs/srv/plugins/hana/srv-mgr");
serviceBindingCache.value = await mtxServiceManager.getAll();
serviceBindingCache.exipreTs = Date.now() + 10 * 60 * 1000;
return serviceBindingCache.value;
return await serviceBindingCache.value;
}

async #selectLastSuccessfulPeriodicTimestamp() {
Expand Down

0 comments on commit 21a2583

Please sign in to comment.