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.
- package/dist/bean/bean.worker.d.ts +3 -3
- package/dist/config/config.d.ts +3 -5
- package/dist/index.js +19 -25
- package/package.json +1 -1
|
@@ -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 |
|
|
7
|
-
exit(code?: number | string | null | undefined):
|
|
8
|
-
exitAll(code?: number | string | null | undefined):
|
|
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
|
}
|
package/dist/config/config.d.ts
CHANGED
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.
|
|
21
|
-
const aliveTimeoutMore = this.scope.config.
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
exit(code) {
|
|
34
|
+
closeApp(false).then(() => {
|
|
35
|
+
process.exit(code);
|
|
36
|
+
});
|
|
36
37
|
}
|
|
37
|
-
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
|
|
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
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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.
|
|
109
|
+
const aliveTimeout = scope.config.alive.timeout;
|
|
116
110
|
// interval
|
|
117
111
|
this._intervalAlive = setInterval(async () => {
|
|
118
112
|
await this.app.bean.worker.setAlive();
|