vona-module-a-worker 5.0.25 → 5.0.27
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/index.js +32 -30
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import { BeanInfo, BeanBase, uuidv4,
|
|
1
|
+
import { BeanInfo, BeanBase, uuidv4, BeanSimple, BeanScopeBase } from 'vona';
|
|
2
|
+
import { __decorate } from 'tslib';
|
|
2
3
|
import cluster from 'node:cluster';
|
|
3
4
|
import { isNil } from '@cabloy/utils';
|
|
4
5
|
import { Bean, Scope } from 'vona-module-a-bean';
|
|
5
6
|
import { Broadcast, BeanBroadcastBase } from 'vona-module-a-broadcast';
|
|
6
7
|
import { CacheRedis, BeanCacheRedisBase } from 'vona-module-a-cache';
|
|
7
8
|
|
|
8
|
-
var _dec$4, _dec2$4, _class$4;
|
|
9
9
|
const SymbolWorkerId = Symbol('SymbolWorkerId');
|
|
10
|
-
let BeanWorker =
|
|
11
|
-
module: "a-worker"
|
|
12
|
-
}), _dec$4(_class$4 = _dec2$4(_class$4 = class BeanWorker extends BeanBase {
|
|
10
|
+
let BeanWorker = class BeanWorker extends BeanBase {
|
|
13
11
|
get id() {
|
|
14
12
|
if (this.app[SymbolWorkerId] === undefined) {
|
|
15
13
|
this.app[SymbolWorkerId] = uuidv4();
|
|
@@ -31,9 +29,10 @@ let BeanWorker = (_dec$4 = Bean(), _dec2$4 = BeanInfo({
|
|
|
31
29
|
return await this.scope.cacheRedis.workerAlive.get(id ?? this.id);
|
|
32
30
|
}
|
|
33
31
|
exit(code) {
|
|
34
|
-
|
|
32
|
+
this.app.close().then(() => {
|
|
35
33
|
process.exit(code);
|
|
36
34
|
});
|
|
35
|
+
this.app.throw(700);
|
|
37
36
|
}
|
|
38
37
|
exitAll(code) {
|
|
39
38
|
this.scope.broadcast.exitAll.emit({
|
|
@@ -43,48 +42,52 @@ let BeanWorker = (_dec$4 = Bean(), _dec2$4 = BeanInfo({
|
|
|
43
42
|
reload() {
|
|
44
43
|
const worker = cluster.worker;
|
|
45
44
|
if (!worker) {
|
|
46
|
-
this.exit(); //
|
|
45
|
+
this.exit(); // docker restart
|
|
47
46
|
} else {
|
|
48
|
-
|
|
47
|
+
this.app.close().then(() => {
|
|
49
48
|
worker.send('reload-worker');
|
|
50
49
|
});
|
|
50
|
+
this.app.throw(701);
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
reloadAll() {
|
|
54
54
|
this.scope.broadcast.reloadAll.emit();
|
|
55
55
|
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
var _dec$3, _dec2$3, _class$3;
|
|
59
|
-
let BroadcastExitAll = (_dec$3 = Broadcast({
|
|
60
|
-
instance: false
|
|
61
|
-
}), _dec2$3 = BeanInfo({
|
|
56
|
+
};
|
|
57
|
+
BeanWorker = __decorate([Bean(), BeanInfo({
|
|
62
58
|
module: "a-worker"
|
|
63
|
-
}),
|
|
59
|
+
})], BeanWorker);
|
|
60
|
+
|
|
61
|
+
let BroadcastExitAll = class BroadcastExitAll extends BeanBroadcastBase {
|
|
64
62
|
async execute(data, _isEmitter) {
|
|
65
63
|
this.bean.worker.exit(data.code);
|
|
66
64
|
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
var _dec$2, _dec2$2, _class$2;
|
|
70
|
-
let BroadcastReloadAll = (_dec$2 = Broadcast({
|
|
65
|
+
};
|
|
66
|
+
BroadcastExitAll = __decorate([Broadcast({
|
|
71
67
|
instance: false
|
|
72
|
-
}),
|
|
68
|
+
}), BeanInfo({
|
|
73
69
|
module: "a-worker"
|
|
74
|
-
}),
|
|
70
|
+
})], BroadcastExitAll);
|
|
71
|
+
|
|
72
|
+
let BroadcastReloadAll = class BroadcastReloadAll extends BeanBroadcastBase {
|
|
75
73
|
async execute(_data, _isEmitter) {
|
|
76
74
|
this.bean.worker.reload();
|
|
77
75
|
}
|
|
78
|
-
}
|
|
76
|
+
};
|
|
77
|
+
BroadcastReloadAll = __decorate([Broadcast({
|
|
78
|
+
instance: false
|
|
79
|
+
}), BeanInfo({
|
|
80
|
+
module: "a-worker"
|
|
81
|
+
})], BroadcastReloadAll);
|
|
79
82
|
|
|
80
|
-
|
|
81
|
-
|
|
83
|
+
let CacheRedisWorkerAlive = class CacheRedisWorkerAlive extends BeanCacheRedisBase {};
|
|
84
|
+
CacheRedisWorkerAlive = __decorate([CacheRedis({
|
|
82
85
|
disableInstance: true,
|
|
83
86
|
disableTransactionCompensate: true,
|
|
84
87
|
client: 'worker'
|
|
85
|
-
}),
|
|
88
|
+
}), BeanInfo({
|
|
86
89
|
module: "a-worker"
|
|
87
|
-
}),
|
|
90
|
+
})], CacheRedisWorkerAlive);
|
|
88
91
|
|
|
89
92
|
function config(app) {
|
|
90
93
|
return {
|
|
@@ -124,11 +127,10 @@ class Monkey extends BeanSimple {
|
|
|
124
127
|
}
|
|
125
128
|
}
|
|
126
129
|
|
|
127
|
-
|
|
128
|
-
|
|
130
|
+
let ScopeModuleAWorker = class ScopeModuleAWorker extends BeanScopeBase {};
|
|
131
|
+
ScopeModuleAWorker = __decorate([Scope(), BeanInfo({
|
|
129
132
|
module: "a-worker"
|
|
130
|
-
}),
|
|
131
|
-
|
|
133
|
+
})], ScopeModuleAWorker);
|
|
132
134
|
/** scope: end */
|
|
133
135
|
|
|
134
136
|
export { BeanWorker, BroadcastExitAll, BroadcastReloadAll, CacheRedisWorkerAlive, Monkey, ScopeModuleAWorker, config };
|