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
+15
-14
No files matched your search
@@ -119,9 +119,8 @@ async function load() {
|
||||
}
|
||||
}
|
||||
}
|
||||
setTimeout(() => {
|
||||
process.exit(0);
|
||||
}, 0);
|
||||
console.log('Unzip done.');
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
module.exports = load;
|
||||
+10
-10
@@ -12,22 +12,21 @@ async function terminate() {
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
async function fork(args) {
|
||||
if (args) {
|
||||
cluster.setupMaster({ args });
|
||||
const r = cluster.fork();
|
||||
cluster.setupMaster({ args: [] });
|
||||
return r;
|
||||
}
|
||||
async function fork(args = []) {
|
||||
cluster.setupMaster({ args, exec: __filename });
|
||||
return cluster.fork();
|
||||
}
|
||||
|
||||
async function entry(config) {
|
||||
if (config.entry) {
|
||||
if (config.newProcess) {
|
||||
const process = await fork([`--entry=${config.entry}`]);
|
||||
await new Promise((resolve) => {
|
||||
process.on('exit', resolve);
|
||||
const p = await fork([`--entry=${config.entry}`]);
|
||||
await new Promise((resolve, reject) => {
|
||||
p.on('exit', resolve);
|
||||
p.on('error', (err) => {
|
||||
p.kill();
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
const loader = require(`./entry/${config.entry}`);
|
||||
@@ -119,6 +118,7 @@ async function load() {
|
||||
}
|
||||
});
|
||||
const cnt = await entry({ entry: 'master' });
|
||||
console.log('Master started');
|
||||
cluster.on('exit', (worker, code, signal) => {
|
||||
console.log(`Worker ${worker.process.pid} ${worker.id} exit: ${code} ${signal}`);
|
||||
});
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
const { EventEmitter } = require('events');
|
||||
const cluster = require('cluster');
|
||||
|
||||
const bus = new EventEmitter();
|
||||
|
||||
@@ -26,7 +27,8 @@ function unsubscribe(events, handler, funcName) {
|
||||
}
|
||||
|
||||
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({
|
||||
event: 'bus',
|
||||
eventName: event,
|
||||
|
||||
Reference in new issue
Block a user