MCPcopy Create free account
hub / github.com/AdaXH/korct / init

Method init

class/Process.ts:29–66  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

27 }
28
29 init(): void {
30 if (cluster.isMaster) {
31 for (let i = 0; i < this.maxProcess; i += 1) {
32 const worker = cluster.fork();
33 setLog(worker);
34 worker.on('message', arg => {
35 if (this.eventListener) {
36 this.eventListener.forEach(({ eventName, callback }) => {
37 if (arg?.eventName === eventName) {
38 logger.info(`event: ${eventName}`);
39 callback();
40 }
41 });
42 }
43 });
44 this.workers.push({
45 pid: worker.process.pid,
46 worker,
47 });
48 }
49 cluster.on('exit', (worker, code, sign) => {
50 const newWorker = cluster.fork();
51 setLog(newWorker);
52 logger.warning(`process exit whitd code: ${code}, sing: ${sign}, now loading`);
53 const newWorkes = this.workers
54 .filter(item => worker.process.pid !== item.pid)
55 .concat([
56 {
57 pid: newWorker.process.pid,
58 worker: newWorker,
59 },
60 ]);
61 this.workers = newWorkes;
62 });
63 } else {
64 this.callback();
65 }
66 }
67}
68
69interface WorkerFace {

Callers 1

startServerMethod · 0.95

Calls 1

setLogFunction · 0.85

Tested by

no test coverage detected