1
0
forked from circlecloud/tera

refactor: rewrite rpc server client

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
2019-07-20 13:12:21 +08:00
parent fd1b23a4c3
commit b05a00f87d
18 changed files with 315 additions and 298 deletions

View File

@@ -30,39 +30,53 @@ function Fork(Path, ArrArgs?): TeraChildProcess {
let ArrMiningWrk = []
function RunProcess() {
console.log(`Start add ${thread} pow process`)
for (var R = 0; R < thread; R++) {
let Worker = Fork('./process/pow-process');
ArrMiningWrk.push(Worker);
Worker.Num = ArrMiningWrk.length;
Worker.on('message', function(msg) {
switch (msg.cmd) {
case "log":
console.log(msg.message)
break;
}
});
Worker.on('error', function(err) {
if (!ArrMiningWrk.length)
return;
console.log('ERROR IN PROCESS: ' + err);
});
Worker.on('close', function(code) {
console.log(`STOP PROCESS: ${Worker.Num} pid: ${Worker.pid} code: ${code}`)
for (var i = 0; i < ArrMiningWrk.length; i++) {
if (ArrMiningWrk[i].pid === Worker.pid) {
console.log("Delete wrk from arr - pid:" + Worker.pid);
ArrMiningWrk.splice(i, 1);
}
}
});
AddPowProcess()
}
}
function AddPowProcess() {
let Worker = Fork('./process/pow-process');
ArrMiningWrk.push(Worker);
Worker.Num = ArrMiningWrk.length;
Worker.on('message', function(msg) {
switch (msg.cmd) {
case "log":
console.log(msg.message)
break;
}
});
Worker.on('error', function(err) {
if (!ArrMiningWrk.length)
return;
console.log('ERROR IN PROCESS: ' + err);
});
Worker.on('close', function(code) {
for (var i = 0; i < ArrMiningWrk.length; i++) {
if (ArrMiningWrk[i].pid === Worker.pid) {
console.log(`STOP PROCESS: ${Worker.Num} pid: ${Worker.pid} code: ${code} delete wrk`);
ArrMiningWrk.splice(i, 1);
}
}
});
}
console.log("START MINER PROCESS COUNT: " + thread + " Memory: " + ProcessMemorySize / 1024 / 1024 + " Mb for each process");
setInterval(() => {
async function CheckAlive() {
if (!ArrMiningWrk.length) {
console.log(`ArrMiningWrk.length == ${ArrMiningWrk.length} Starting all node...`)
RunProcess();
}
}, 1000)
if (ArrMiningWrk.length < thread) {
AddPowProcess()
}
setTimeout(CheckAlive, 1000)
}
async function main() {
await CheckAlive()
}
main()