@cap-js-community/event-queue 2.1.1 → 2.1.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": "2.1.
|
|
3
|
+
"version": "2.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
|
"types": "src/index.d.ts",
|
|
@@ -1110,13 +1110,15 @@ class EventQueueProcessorBase {
|
|
|
1110
1110
|
}
|
|
1111
1111
|
}
|
|
1112
1112
|
|
|
1113
|
-
#calculateCronDates() {
|
|
1113
|
+
#calculateCronDates(queueEntry) {
|
|
1114
1114
|
if (!this.#eventConfig.cron) {
|
|
1115
1115
|
return null;
|
|
1116
1116
|
}
|
|
1117
1117
|
|
|
1118
|
-
// NOTE:
|
|
1118
|
+
// NOTE: base the calculation on the planned startAfter if the event was picked up early; otherwise on now to always calc. a future date
|
|
1119
|
+
const currentDate = new Date(Math.max(Date.now(), new Date(queueEntry.startAfter).getTime()));
|
|
1119
1120
|
const cronExpression = CronExpressionParser.parse(this.#eventConfig.cron, {
|
|
1121
|
+
currentDate,
|
|
1120
1122
|
tz: this.#eventConfig.tz,
|
|
1121
1123
|
});
|
|
1122
1124
|
return cronExpression.next();
|
|
@@ -1124,7 +1126,7 @@ class EventQueueProcessorBase {
|
|
|
1124
1126
|
|
|
1125
1127
|
async scheduleNextPeriodEvent(queueEntry) {
|
|
1126
1128
|
const intervalInMs = this.#eventConfig.cron ? null : this.#eventConfig.interval * 1000;
|
|
1127
|
-
const next = this.#calculateCronDates();
|
|
1129
|
+
const next = this.#calculateCronDates(queueEntry);
|
|
1128
1130
|
let newStartAfter;
|
|
1129
1131
|
|
|
1130
1132
|
if (this.#eventConfig.cron) {
|
|
@@ -1167,7 +1169,8 @@ class EventQueueProcessorBase {
|
|
|
1167
1169
|
})
|
|
1168
1170
|
);
|
|
1169
1171
|
this.tx._skipEventQueueBroadcast = false;
|
|
1170
|
-
|
|
1172
|
+
const msUntilNextOccurrence = intervalInMs ?? newEvent.startAfter.getTime() - Date.now();
|
|
1173
|
+
if (msUntilNextOccurrence < this.#config.runInterval * 1.5) {
|
|
1171
1174
|
this.#handleDelayedEvents([newEvent], { skipExcludeDelayedEventIds: true });
|
|
1172
1175
|
const { relative: relativeAfterSchedule } = this.#eventSchedulerInstance.calculateOffset(
|
|
1173
1176
|
this.#eventType,
|