oak-backend-base 4.1.10 → 4.1.11

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.
@@ -16,6 +16,8 @@ export declare class AppLoader<ED extends EntityDict & BaseEntityDict, Cxt exten
16
16
  protected synchronizer?: Synchronizer<ED, Cxt>;
17
17
  protected contextBuilder: (store: DbStore<ED, Cxt>) => Cxt;
18
18
  private nsSocket?;
19
+ private watcherTimerId?;
20
+ private scheduledJobs;
19
21
  private requireSth;
20
22
  protected makeContext(cxtStr?: string, headers?: IncomingHttpHeaders): Promise<Cxt>;
21
23
  /**
package/lib/AppLoader.js CHANGED
@@ -24,6 +24,8 @@ class AppLoader extends types_1.AppLoader {
24
24
  synchronizer;
25
25
  contextBuilder;
26
26
  nsSocket;
27
+ watcherTimerId;
28
+ scheduledJobs = {};
27
29
  requireSth(filePath) {
28
30
  const depFilePath = (0, path_1.join)(this.path, filePath);
29
31
  let sth;
@@ -149,6 +151,14 @@ class AppLoader extends types_1.AppLoader {
149
151
  this.dbStore.connect();
150
152
  }
151
153
  async unmount() {
154
+ if (this.watcherTimerId) {
155
+ console.log('取消watcher...');
156
+ clearTimeout(this.watcherTimerId);
157
+ }
158
+ for (const job in this.scheduledJobs) {
159
+ console.log(`取消定时任务【${job}】...`);
160
+ this.scheduledJobs[job].cancel();
161
+ }
152
162
  (0, index_1.clearPorts)();
153
163
  this.dbStore.disconnect();
154
164
  }
@@ -369,7 +379,7 @@ class AppLoader extends types_1.AppLoader {
369
379
  catch (err) {
370
380
  console.error(`执行了checkpoint,发生错误:`, err);
371
381
  }
372
- setTimeout(() => doWatchers(), 120000);
382
+ this.watcherTimerId = setTimeout(() => doWatchers(), 120000);
373
383
  };
374
384
  doWatchers();
375
385
  }
@@ -382,7 +392,7 @@ class AppLoader extends types_1.AppLoader {
382
392
  if (timers) {
383
393
  for (const timer of timers) {
384
394
  const { cron, name } = timer;
385
- (0, node_schedule_1.scheduleJob)(name, cron, async (date) => {
395
+ const job = (0, node_schedule_1.scheduleJob)(name, cron, async (date) => {
386
396
  const start = Date.now();
387
397
  console.log(`定时器【${name}】开始执行,时间是【${date.toLocaleTimeString()}】`);
388
398
  if (timer.hasOwnProperty('entity')) {
@@ -391,7 +401,7 @@ class AppLoader extends types_1.AppLoader {
391
401
  console.log(`定时器【${name}】执行成功,耗时${Date.now() - start}毫秒】,结果是`, result);
392
402
  }
393
403
  catch (err) {
394
- console.log(`定时器【${name}】执行成功,耗时${Date.now() - start}毫秒】,错误是`, err);
404
+ console.warn(`定时器【${name}】执行失败,耗时${Date.now() - start}毫秒】,错误是`, err);
395
405
  }
396
406
  }
397
407
  else {
@@ -414,6 +424,11 @@ class AppLoader extends types_1.AppLoader {
414
424
  }
415
425
  }
416
426
  });
427
+ if (this.scheduledJobs[name]) {
428
+ // console.error(`定时器【${name}】已经存在,请检查定时器名称是否重复`);
429
+ throw new Error(`定时器【${name}】已经存在,请检查定时器名称是否重复`);
430
+ }
431
+ this.scheduledJobs[name] = job;
417
432
  }
418
433
  }
419
434
  }
@@ -424,7 +439,7 @@ class AppLoader extends types_1.AppLoader {
424
439
  const start = Date.now();
425
440
  try {
426
441
  const result = await this.execWatcher(routine);
427
- console.warn(`例程【${routine.name}】执行成功,耗时${Date.now() - start}毫秒,结果是`, result);
442
+ console.log(`例程【${routine.name}】执行成功,耗时${Date.now() - start}毫秒,结果是`, result);
428
443
  }
429
444
  catch (err) {
430
445
  console.warn(`例程【${routine.name}】执行失败,耗时${Date.now() - start}毫秒,错误是`, err);
@@ -111,7 +111,7 @@ class Synchronizer {
111
111
  remoteEntityId: entityId,
112
112
  data: queue.map((ele) => ({
113
113
  entity: ele.oper.targetEntity,
114
- rowIds: ele.oper.filter.id.$in,
114
+ rowIds: ele.oper.filter.id.$in, // 暂时应该没什么用
115
115
  action: ele.oper.action,
116
116
  data: ele.oper.data,
117
117
  })),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oak-backend-base",
3
- "version": "4.1.10",
3
+ "version": "4.1.11",
4
4
  "description": "oak-backend-base",
5
5
  "main": "lib/index",
6
6
  "author": {
@@ -22,8 +22,8 @@
22
22
  "node-schedule": "^2.1.0",
23
23
  "oak-common-aspect": "^3.0.4",
24
24
  "oak-db": "^3.3.2",
25
- "oak-domain": "^5.1.10",
26
- "oak-frontend-base": "^5.3.19",
25
+ "oak-domain": "^5.1.11",
26
+ "oak-frontend-base": "^5.3.20",
27
27
  "socket.io": "^4.7.2",
28
28
  "socket.io-client": "^4.7.2",
29
29
  "uuid": "^8.3.2"