@cap-js-community/event-queue 2.1.0-beta.0 → 2.1.0-beta.1
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.0-beta.
|
|
3
|
+
"version": "2.1.0-beta.1",
|
|
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",
|
|
@@ -22,8 +22,6 @@
|
|
|
22
22
|
"multi-tenancy"
|
|
23
23
|
],
|
|
24
24
|
"scripts": {
|
|
25
|
-
"start": "PORT=4005 cds-serve",
|
|
26
|
-
"watch": "PORT=4005 cds watch",
|
|
27
25
|
"test:unit": "jest --selectProjects unit",
|
|
28
26
|
"test:integration": "jest --selectProjects integration --runInBand",
|
|
29
27
|
"voter:test:integration": "jest --selectProjects integration",
|
|
@@ -38,13 +36,12 @@
|
|
|
38
36
|
"eslint:ci": "eslint .",
|
|
39
37
|
"prettier": "prettier --write --loglevel error .",
|
|
40
38
|
"prettier:ci": "prettier --check .",
|
|
41
|
-
"prepareRelease": "npm prune --production",
|
|
42
39
|
"docs": "cd docs && bundle exec jekyll serve",
|
|
43
40
|
"docs:install": "cd docs && npx shx rm -rf vendor Gemfile.lock && bundle install",
|
|
44
41
|
"upgrade-lock": "npx shx rm -rf package-lock.json node_modules && npm i --package-lock"
|
|
45
42
|
},
|
|
46
43
|
"engines": {
|
|
47
|
-
"node": ">=
|
|
44
|
+
"node": ">=20"
|
|
48
45
|
},
|
|
49
46
|
"dependencies": {
|
|
50
47
|
"@cap-js-community/common": "^0.3.4",
|
|
@@ -408,7 +408,7 @@ class EventQueueProcessorBase {
|
|
|
408
408
|
UPDATE.entity(this.#config.tableNameEventQueue)
|
|
409
409
|
.set({
|
|
410
410
|
status: status,
|
|
411
|
-
...(error && { error: this
|
|
411
|
+
...(error && { error: this._error2String(error) }),
|
|
412
412
|
})
|
|
413
413
|
.where({
|
|
414
414
|
ID: queueEntryIds,
|
|
@@ -498,7 +498,7 @@ class EventQueueProcessorBase {
|
|
|
498
498
|
}
|
|
499
499
|
|
|
500
500
|
if (data.error) {
|
|
501
|
-
data.error = this
|
|
501
|
+
data.error = this._error2String(data.error);
|
|
502
502
|
}
|
|
503
503
|
|
|
504
504
|
if (!data.startAfter && [EventProcessingStatus.Error, EventProcessingStatus.Open].includes(data.status)) {
|
|
@@ -535,7 +535,7 @@ class EventQueueProcessorBase {
|
|
|
535
535
|
});
|
|
536
536
|
}
|
|
537
537
|
|
|
538
|
-
|
|
538
|
+
_error2String(error) {
|
|
539
539
|
return JSON.stringify(error, (_, value) => this.#errorReplacer(value));
|
|
540
540
|
}
|
|
541
541
|
|
|
@@ -312,6 +312,10 @@ class EventQueueGenericOutboxHandler extends EventQueueBaseClass {
|
|
|
312
312
|
return genericHandler ?? null;
|
|
313
313
|
}
|
|
314
314
|
|
|
315
|
+
if (event.endsWith(EVENT_QUEUE_ACTIONS.SAGA_SUCCESS)) {
|
|
316
|
+
[event] = event.split("/");
|
|
317
|
+
}
|
|
318
|
+
|
|
315
319
|
const specificHandler = this.__onHandlers[[event, saga].join("/")];
|
|
316
320
|
if (specificHandler) {
|
|
317
321
|
return specificHandler;
|
|
@@ -351,18 +355,17 @@ class EventQueueGenericOutboxHandler extends EventQueueBaseClass {
|
|
|
351
355
|
}
|
|
352
356
|
|
|
353
357
|
async processEvent(processContext, key, queueEntries, payload) {
|
|
358
|
+
let statusTuple;
|
|
359
|
+
const { userId, invocationFn, reg } = this.#buildDispatchData(processContext, payload, { key, queueEntries });
|
|
354
360
|
try {
|
|
355
|
-
const { userId, invocationFn, reg } = this.#buildDispatchData(processContext, payload, { key, queueEntries });
|
|
356
361
|
await this.#setContextUser(processContext, userId, reg);
|
|
357
362
|
const result = await this.__srvUnboxed.tx(processContext)[invocationFn](reg);
|
|
358
|
-
|
|
359
|
-
await this.#publishFollowupEvents(processContext, reg, statusTuple);
|
|
360
|
-
return statusTuple;
|
|
363
|
+
statusTuple = this.#determineResultStatus(result, queueEntries);
|
|
361
364
|
} catch (err) {
|
|
362
365
|
this.logger.error("error processing outboxed service call", err, {
|
|
363
366
|
serviceName: this.eventSubType,
|
|
364
367
|
});
|
|
365
|
-
|
|
368
|
+
statusTuple = queueEntries.map((queueEntry) => [
|
|
366
369
|
queueEntry.ID,
|
|
367
370
|
{
|
|
368
371
|
status: EventProcessingStatus.Error,
|
|
@@ -370,6 +373,9 @@ class EventQueueGenericOutboxHandler extends EventQueueBaseClass {
|
|
|
370
373
|
},
|
|
371
374
|
]);
|
|
372
375
|
}
|
|
376
|
+
|
|
377
|
+
await this.#publishFollowupEvents(processContext, reg, statusTuple);
|
|
378
|
+
return statusTuple;
|
|
373
379
|
}
|
|
374
380
|
|
|
375
381
|
async #publishFollowupEvents(processContext, req, statusTuple) {
|
|
@@ -380,7 +386,7 @@ class EventQueueGenericOutboxHandler extends EventQueueBaseClass {
|
|
|
380
386
|
return;
|
|
381
387
|
}
|
|
382
388
|
|
|
383
|
-
if (req.event.endsWith(EVENT_QUEUE_ACTIONS.
|
|
389
|
+
if (req.event.endsWith(EVENT_QUEUE_ACTIONS.SAGA_FAILED)) {
|
|
384
390
|
return;
|
|
385
391
|
}
|
|
386
392
|
|
|
@@ -393,23 +399,32 @@ class EventQueueGenericOutboxHandler extends EventQueueBaseClass {
|
|
|
393
399
|
}
|
|
394
400
|
|
|
395
401
|
for (const [, result] of statusTuple) {
|
|
396
|
-
|
|
397
|
-
|
|
402
|
+
const data = result.nextData ?? req.data;
|
|
403
|
+
if (
|
|
404
|
+
succeeded &&
|
|
405
|
+
result.status === EventProcessingStatus.Done &&
|
|
406
|
+
!req.event.endsWith(EVENT_QUEUE_ACTIONS.SAGA_SUCCESS)
|
|
407
|
+
) {
|
|
408
|
+
await this.__srv.tx(processContext).send(succeeded, data);
|
|
398
409
|
}
|
|
399
410
|
|
|
400
411
|
if (failed && result.status === EventProcessingStatus.Error) {
|
|
401
|
-
|
|
412
|
+
result.error && (data.error = this._error2String(result.error));
|
|
413
|
+
await this.__srv.tx(processContext).send(failed, data);
|
|
402
414
|
}
|
|
403
415
|
|
|
404
416
|
delete result.nextData;
|
|
405
417
|
}
|
|
406
418
|
|
|
407
419
|
if (config.insertEventsBeforeCommit) {
|
|
408
|
-
this.nextSagaEvents = tx._eventQueue
|
|
420
|
+
this.nextSagaEvents = tx._eventQueue?.events;
|
|
409
421
|
} else {
|
|
410
|
-
this.nextSagaEvents = tx._eventQueue
|
|
422
|
+
this.nextSagaEvents = tx._eventQueue?.events.filter((event) => JSON.parse(event.payload).event === failed);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
if (tx._eventQueue) {
|
|
426
|
+
tx._eventQueue.events = nextEvents ?? [];
|
|
411
427
|
}
|
|
412
|
-
tx._eventQueue.events = nextEvents ?? [];
|
|
413
428
|
}
|
|
414
429
|
|
|
415
430
|
#determineResultStatus(result, queueEntries) {
|