oak-backend-base 4.1.24 → 4.1.25
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/lib/AppLoader.d.ts +1 -0
- package/lib/AppLoader.js +41 -2
- package/package.json +2 -2
package/lib/AppLoader.d.ts
CHANGED
|
@@ -62,5 +62,6 @@ export declare class AppLoader<ED extends EntityDict & BaseEntityDict, Cxt exten
|
|
|
62
62
|
protected execFreeTimer(timer: FreeTimer<ED, Cxt>, context: Cxt): Promise<OperationResult<ED>> | undefined;
|
|
63
63
|
startTimers(): void;
|
|
64
64
|
execStartRoutines(): Promise<void>;
|
|
65
|
+
execStopRoutines(): Promise<void>;
|
|
65
66
|
execRoutine(routine: <Cxt extends AsyncContext<ED>>(context: Cxt) => Promise<void>): Promise<void>;
|
|
66
67
|
}
|
package/lib/AppLoader.js
CHANGED
|
@@ -59,13 +59,15 @@ class AppLoader extends types_1.AppLoader {
|
|
|
59
59
|
const errorToPublish = (0, lodash_1.cloneDeep)(err);
|
|
60
60
|
await Promise.all(this.internalErrorHandlers.map((handler) => {
|
|
61
61
|
return new Promise(async (resolve) => {
|
|
62
|
+
const ctx = await this.makeContext();
|
|
62
63
|
try {
|
|
63
|
-
const ctx = await this.makeContext();
|
|
64
64
|
console.log(`调用internalErrorHandler【${handler.name}】处理内部错误事件`);
|
|
65
|
-
handler.handle(ctx, type, message, errorToPublish);
|
|
65
|
+
await handler.handle(ctx, type, message, errorToPublish);
|
|
66
|
+
await ctx.commit();
|
|
66
67
|
}
|
|
67
68
|
catch (e) {
|
|
68
69
|
console.error('执行internalErrorHandler时出错', e);
|
|
70
|
+
await ctx.rollback();
|
|
69
71
|
}
|
|
70
72
|
finally {
|
|
71
73
|
resolve();
|
|
@@ -513,6 +515,7 @@ class AppLoader extends types_1.AppLoader {
|
|
|
513
515
|
async execStartRoutines() {
|
|
514
516
|
const routines = this.requireSth('lib/routines/start') || [];
|
|
515
517
|
for (const routine of routines) {
|
|
518
|
+
console.log(`执行启动例程【${routine.name}】...`);
|
|
516
519
|
if (routine.hasOwnProperty('entity')) {
|
|
517
520
|
const start = Date.now();
|
|
518
521
|
try {
|
|
@@ -531,6 +534,42 @@ class AppLoader extends types_1.AppLoader {
|
|
|
531
534
|
try {
|
|
532
535
|
const result = await routineFn(context, {
|
|
533
536
|
socket: this.nsSocket,
|
|
537
|
+
contextBuilder: () => this.makeContext(),
|
|
538
|
+
});
|
|
539
|
+
console.log(`例程【${name}】执行成功,耗时${Date.now() - start}毫秒,结果是【${result}】`);
|
|
540
|
+
await context.commit();
|
|
541
|
+
}
|
|
542
|
+
catch (err) {
|
|
543
|
+
console.error(`例程【${name}】执行失败,耗时${Date.now() - start}毫秒,错误是`, err);
|
|
544
|
+
await context.rollback();
|
|
545
|
+
throw err;
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
async execStopRoutines() {
|
|
551
|
+
const routines = this.requireSth('lib/routines/stop') || [];
|
|
552
|
+
for (const routine of routines) {
|
|
553
|
+
console.log(`执行停止例程【${routine.name}】...`);
|
|
554
|
+
if (routine.hasOwnProperty('entity')) {
|
|
555
|
+
const start = Date.now();
|
|
556
|
+
try {
|
|
557
|
+
const result = await this.execWatcher(routine);
|
|
558
|
+
console.log(`例程【${routine.name}】执行成功,耗时${Date.now() - start}毫秒,结果是`, result);
|
|
559
|
+
}
|
|
560
|
+
catch (err) {
|
|
561
|
+
console.error(`例程【${routine.name}】执行失败,耗时${Date.now() - start}毫秒,错误是`, err);
|
|
562
|
+
throw err;
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
else {
|
|
566
|
+
const { name, routine: routineFn } = routine;
|
|
567
|
+
const context = await this.makeContext();
|
|
568
|
+
const start = Date.now();
|
|
569
|
+
try {
|
|
570
|
+
const result = await routineFn(context, {
|
|
571
|
+
socket: this.nsSocket,
|
|
572
|
+
contextBuilder: () => this.makeContext(),
|
|
534
573
|
});
|
|
535
574
|
console.log(`例程【${name}】执行成功,耗时${Date.now() - start}毫秒,结果是【${result}】`);
|
|
536
575
|
await context.commit();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oak-backend-base",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.25",
|
|
4
4
|
"description": "oak-backend-base",
|
|
5
5
|
"main": "lib/index",
|
|
6
6
|
"author": {
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"node-schedule": "^2.1.0",
|
|
24
24
|
"oak-common-aspect": "^3.0.5",
|
|
25
25
|
"oak-db": "^3.3.11",
|
|
26
|
-
"oak-domain": "^5.1.
|
|
26
|
+
"oak-domain": "^5.1.31",
|
|
27
27
|
"oak-frontend-base": "^5.3.43",
|
|
28
28
|
"socket.io": "^4.8.1",
|
|
29
29
|
"socket.io-client": "^4.7.2",
|