mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
重启功能
This commit is contained in:
1 parent
a29b801e72
commit
2aeacb04ab
10 files changed
+49
-41
No files matched your search
+21
-3
@@ -20,6 +20,25 @@ async function entry(config) {
|
||||
}
|
||||
}
|
||||
|
||||
async function stopWorker() {
|
||||
cluster.disconnect();
|
||||
}
|
||||
|
||||
async function startWorker() {
|
||||
for (let i = 0; i < numCPUs; i++) {
|
||||
cluster.fork();
|
||||
}
|
||||
}
|
||||
|
||||
async function messageHandler(worker, msg) {
|
||||
if (msg.event && msg.event === 'restart') {
|
||||
console.log('Restarting');
|
||||
await stopWorker();
|
||||
console.log('Worker stopped');
|
||||
await startWorker();
|
||||
}
|
||||
}
|
||||
|
||||
async function load() {
|
||||
global.nodeModules = {
|
||||
bson: require('bson'),
|
||||
@@ -65,9 +84,8 @@ async function load() {
|
||||
cluster.on('online', (worker) => {
|
||||
console.log(`Worker ${worker.process.pid} is online`);
|
||||
});
|
||||
for (let i = 0; i < numCPUs; i++) {
|
||||
cluster.fork();
|
||||
}
|
||||
cluster.on('message', messageHandler);
|
||||
await startWorker();
|
||||
} else {
|
||||
console.log(`Worker ${process.pid} Starting`);
|
||||
await entry({ entry: 'worker' });
|
||||
|
||||
Reference in new issue
Block a user