vona-module-a-worker 5.0.21 → 5.0.23

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.
@@ -3,9 +3,9 @@ export declare class BeanWorker extends BeanBase {
3
3
  get id(): string;
4
4
  setAlive(id?: string): Promise<void>;
5
5
  delAlive(id?: string): Promise<void>;
6
- getAlive(id?: string): Promise<boolean | null | undefined>;
7
- exit(code?: number | string | null | undefined): Promise<void>;
8
- exitAll(code?: number | string | null | undefined): Promise<void>;
6
+ getAlive(id?: string): Promise<boolean | undefined>;
7
+ exit(code?: number | string | null | undefined): void;
8
+ exitAll(code?: number | string | null | undefined): void;
9
9
  reload(): void;
10
10
  reloadAll(): void;
11
11
  }
@@ -1,9 +1,7 @@
1
1
  import type { VonaApplication } from 'vona';
2
2
  export declare function config(app: VonaApplication): {
3
- worker: {
4
- alive: {
5
- timeout: number;
6
- timeoutMore: number;
7
- };
3
+ alive: {
4
+ timeout: number;
5
+ timeoutMore: number;
8
6
  };
9
7
  };
package/dist/index.js CHANGED
@@ -17,8 +17,8 @@ let BeanWorker = (_dec$4 = Bean(), _dec2$4 = BeanInfo({
17
17
  return this.app[SymbolWorkerId];
18
18
  }
19
19
  async setAlive(id) {
20
- const aliveTimeout = this.scope.config.worker.alive.timeout;
21
- const aliveTimeoutMore = this.scope.config.worker.alive.timeoutMore;
20
+ const aliveTimeout = this.scope.config.alive.timeout;
21
+ const aliveTimeoutMore = this.scope.config.alive.timeoutMore;
22
22
  await this.scope.cacheRedis.workerAlive.set(true, id ?? this.id, {
23
23
  ttl: aliveTimeout + aliveTimeoutMore
24
24
  });
@@ -30,11 +30,12 @@ let BeanWorker = (_dec$4 = Bean(), _dec2$4 = BeanInfo({
30
30
  if (isNil(id) || id === this.id) return true;
31
31
  return await this.scope.cacheRedis.workerAlive.get(id ?? this.id);
32
32
  }
33
- async exit(code) {
34
- await this.app.meta.close();
35
- process.exit(code);
33
+ exit(code) {
34
+ closeApp(false).then(() => {
35
+ process.exit(code);
36
+ });
36
37
  }
37
- async exitAll(code) {
38
+ exitAll(code) {
38
39
  this.scope.broadcast.exitAll.emit({
39
40
  code
40
41
  });
@@ -42,20 +43,14 @@ let BeanWorker = (_dec$4 = Bean(), _dec2$4 = BeanInfo({
42
43
  reload() {
43
44
  const worker = cluster.worker;
44
45
  if (!worker) {
45
- return;
46
- // maybe throw uncaughtException
47
- // throw new Error('Only take affect in cluster');
46
+ this.exit(); // pm2 or forever
47
+ } else {
48
+ closeApp(false).then(() => {
49
+ worker.send('reload-worker');
50
+ });
48
51
  }
49
- closeApp(false).then(() => {
50
- worker.send('reload-worker');
51
- });
52
52
  }
53
53
  reloadAll() {
54
- if (!cluster.worker) {
55
- return;
56
- // maybe throw uncaughtException
57
- // throw new Error('Only take affect in cluster');
58
- }
59
54
  this.scope.broadcast.reloadAll.emit();
60
55
  }
61
56
  }) || _class$4) || _class$4);
@@ -67,7 +62,7 @@ let BroadcastExitAll = (_dec$3 = Broadcast({
67
62
  module: "a-worker"
68
63
  }), _dec$3(_class$3 = _dec2$3(_class$3 = class BroadcastExitAll extends BeanBroadcastBase {
69
64
  async execute(data, _isEmitter) {
70
- await this.bean.worker.exit(data.code);
65
+ this.bean.worker.exit(data.code);
71
66
  }
72
67
  }) || _class$3) || _class$3);
73
68
 
@@ -85,18 +80,17 @@ let BroadcastReloadAll = (_dec$2 = Broadcast({
85
80
  var _dec$1, _dec2$1, _class$1;
86
81
  let CacheRedisWorkerAlive = (_dec$1 = CacheRedis({
87
82
  disableInstance: true,
88
- disableTransactionCompensate: true
83
+ disableTransactionCompensate: true,
84
+ client: 'worker'
89
85
  }), _dec2$1 = BeanInfo({
90
86
  module: "a-worker"
91
87
  }), _dec$1(_class$1 = _dec2$1(_class$1 = class CacheRedisWorkerAlive extends BeanCacheRedisBase {}) || _class$1) || _class$1);
92
88
 
93
89
  function config(app) {
94
90
  return {
95
- worker: {
96
- alive: {
97
- timeout: app.meta.isProd ? 3000 : 1000,
98
- timeoutMore: app.meta.isProd ? 3000 : 1000
99
- }
91
+ alive: {
92
+ timeout: app.meta.isProd ? 3000 : 1000,
93
+ timeoutMore: app.meta.isProd ? 3000 : 1000
100
94
  }
101
95
  };
102
96
  }
@@ -112,7 +106,7 @@ class Monkey extends BeanSimple {
112
106
  async moduleLoaded(module) {
113
107
  if (module.info.relativeName !== __ThisModule__) return;
114
108
  const scope = this.app.scope(__ThisModule__);
115
- const aliveTimeout = scope.config.worker.alive.timeout;
109
+ const aliveTimeout = scope.config.alive.timeout;
116
110
  // interval
117
111
  this._intervalAlive = setInterval(async () => {
118
112
  await this.app.bean.worker.setAlive();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vona-module-a-worker",
3
3
  "type": "module",
4
- "version": "5.0.21",
4
+ "version": "5.0.23",
5
5
  "title": "a-worker",
6
6
  "vonaModule": {
7
7
  "dependencies": {},