pwi-plata-type 0.3.11 → 0.3.12
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/libs/cluster.ts +34 -1
- package/package.json +1 -1
package/libs/cluster.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PlataRequire, PlataDirs, PlataFiles } from './tools'
|
|
1
|
+
import { PlataRequire, PlataDirs, PlataFiles, PlataResultado } from './tools'
|
|
2
2
|
import { cpus } from 'node:os'
|
|
3
3
|
import * as typeCluster from 'node:cluster'
|
|
4
4
|
|
|
@@ -169,6 +169,16 @@ export class PlataClusterManager {
|
|
|
169
169
|
}
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
+
private async sendAllWorkers(msg: PlataClusterMsg) {
|
|
173
|
+
if (this.Cluster.workers === undefined) return
|
|
174
|
+
|
|
175
|
+
for (const worker of Object.values(this.Cluster.workers)) {
|
|
176
|
+
if (worker === undefined) continue
|
|
177
|
+
|
|
178
|
+
worker.send(msg)
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
172
182
|
private async _clusterMsgServer(_worker: typeCluster.Worker, msg: PlataClusterMsg) {
|
|
173
183
|
if (msg.name !== '_plata') {
|
|
174
184
|
// TODO :::
|
|
@@ -178,7 +188,30 @@ export class PlataClusterManager {
|
|
|
178
188
|
console.log('Solicitado kill do app')
|
|
179
189
|
process.exit(0)
|
|
180
190
|
;
|
|
191
|
+
case 'ECHO':
|
|
192
|
+
this.sendAllWorkers(msg.data.msg)
|
|
193
|
+
return
|
|
194
|
+
;
|
|
181
195
|
}
|
|
182
196
|
}
|
|
183
197
|
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export async function send(msg: PlataClusterMsg): Promise<PlataResultado<boolean>> {
|
|
201
|
+
if (process.send === undefined) {
|
|
202
|
+
return {
|
|
203
|
+
errorID: 'PBLCLWS0001',
|
|
204
|
+
msg: `Erro interno no cluster da plataforma`
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
process.send({
|
|
209
|
+
name: '_plata',
|
|
210
|
+
data: {
|
|
211
|
+
action: 'ECHO',
|
|
212
|
+
msg
|
|
213
|
+
}
|
|
214
|
+
} as PlataClusterMsg)
|
|
215
|
+
|
|
216
|
+
return true
|
|
184
217
|
}
|