mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
fix #6
This commit is contained in:
1 parent
491ac20974
commit
1074c21c00
3 files changed
+14
-13
No files matched your search
@@ -119,9 +119,8 @@ async function load() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setTimeout(() => {
|
console.log('Unzip done.');
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = load;
|
module.exports = load;
|
||||||
+10
-10
@@ -12,22 +12,21 @@ async function terminate() {
|
|||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fork(args) {
|
async function fork(args = []) {
|
||||||
if (args) {
|
cluster.setupMaster({ args, exec: __filename });
|
||||||
cluster.setupMaster({ args });
|
|
||||||
const r = cluster.fork();
|
|
||||||
cluster.setupMaster({ args: [] });
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
return cluster.fork();
|
return cluster.fork();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function entry(config) {
|
async function entry(config) {
|
||||||
if (config.entry) {
|
if (config.entry) {
|
||||||
if (config.newProcess) {
|
if (config.newProcess) {
|
||||||
const process = await fork([`--entry=${config.entry}`]);
|
const p = await fork([`--entry=${config.entry}`]);
|
||||||
await new Promise((resolve) => {
|
await new Promise((resolve, reject) => {
|
||||||
process.on('exit', resolve);
|
p.on('exit', resolve);
|
||||||
|
p.on('error', (err) => {
|
||||||
|
p.kill();
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
const loader = require(`./entry/${config.entry}`);
|
const loader = require(`./entry/${config.entry}`);
|
||||||
@@ -119,6 +118,7 @@ async function load() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
const cnt = await entry({ entry: 'master' });
|
const cnt = await entry({ entry: 'master' });
|
||||||
|
console.log('Master started');
|
||||||
cluster.on('exit', (worker, code, signal) => {
|
cluster.on('exit', (worker, code, signal) => {
|
||||||
console.log(`Worker ${worker.process.pid} ${worker.id} exit: ${code} ${signal}`);
|
console.log(`Worker ${worker.process.pid} ${worker.id} exit: ${code} ${signal}`);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
const { EventEmitter } = require('events');
|
const { EventEmitter } = require('events');
|
||||||
|
const cluster = require('cluster');
|
||||||
|
|
||||||
const bus = new EventEmitter();
|
const bus = new EventEmitter();
|
||||||
|
|
||||||
@@ -26,7 +27,8 @@ function unsubscribe(events, handler, funcName) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function publish(event, payload, isMaster = true) {
|
function publish(event, payload, isMaster = true) {
|
||||||
if (isMaster && process.send) {
|
// Process forked by pm2 would also have process.send
|
||||||
|
if (isMaster && process.send && !cluster.isMaster) {
|
||||||
process.send({
|
process.send({
|
||||||
event: 'bus',
|
event: 'bus',
|
||||||
eventName: event,
|
eventName: event,
|
||||||
|
|||||||
Reference in new issue
Block a user