mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
拆分unzip工作进程
This commit is contained in:
1 parent
d040b153a1
commit
b54c22cb84
5 files changed
+142
-11
No files matched your search
@@ -21,11 +21,9 @@ async function load(call) {
|
||||
ensureDir(path.resolve(os.tmpdir(), 'hydro'));
|
||||
ensureDir(path.resolve(os.tmpdir(), 'hydro', 'tmp'));
|
||||
ensureDir(path.resolve(os.tmpdir(), 'hydro', 'public'));
|
||||
// TODO better run in another process as this needs lots of memory
|
||||
await call({ entry: 'unzip', newProcess: true });
|
||||
let pending = await require('../lib/hpm').getInstalled();
|
||||
const fail = [];
|
||||
const active = [];
|
||||
require('../lib/i18n');
|
||||
require('../utils');
|
||||
require('../error');
|
||||
|
||||
@@ -31,6 +31,10 @@ for (const i of moduleRoots) {
|
||||
}
|
||||
}
|
||||
async function load() {
|
||||
process.on('unhandledRejection', (e) => {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
});
|
||||
const files = fs.readdirSync(moduleRoot);
|
||||
const t = ['service', 'lib', 'model', 'handler', 'script'];
|
||||
ensureDir(`${os.tmpdir()}/hydro`);
|
||||
@@ -115,6 +119,9 @@ async function load() {
|
||||
}
|
||||
}
|
||||
}
|
||||
setTimeout(() => {
|
||||
process.exit(0);
|
||||
}, 0);
|
||||
}
|
||||
|
||||
module.exports = load;
|
||||
+25
-5
@@ -2,6 +2,7 @@
|
||||
/* eslint-disable no-await-in-loop */
|
||||
/* eslint-disable no-eval */
|
||||
const cluster = require('cluster');
|
||||
const { argv } = require('yargs');
|
||||
|
||||
async function terminate() {
|
||||
for (const task of global.onDestory) {
|
||||
@@ -11,11 +12,28 @@ async function terminate() {
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
async function fork(args) {
|
||||
if (args) {
|
||||
cluster.setupMaster({ args });
|
||||
const r = cluster.fork();
|
||||
cluster.setupMaster({ args: [] });
|
||||
return r;
|
||||
}
|
||||
return cluster.fork();
|
||||
}
|
||||
|
||||
async function entry(config) {
|
||||
if (config.entry) {
|
||||
// TODO newProcess
|
||||
const loader = require(`./entry/${config.entry}`);
|
||||
return await loader(entry);
|
||||
if (config.newProcess) {
|
||||
const process = await fork([`--entry=${config.entry}`]);
|
||||
await new Promise((resolve) => {
|
||||
process.on('exit', resolve);
|
||||
});
|
||||
} else {
|
||||
const loader = require(`./entry/${config.entry}`);
|
||||
return await loader(entry);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -25,9 +43,7 @@ async function stopWorker() {
|
||||
}
|
||||
|
||||
async function startWorker(cnt) {
|
||||
for (let i = 0; i < cnt; i++) {
|
||||
cluster.fork();
|
||||
}
|
||||
for (let i = 0; i < cnt; i++) await fork();
|
||||
}
|
||||
|
||||
async function executeCommand(input) {
|
||||
@@ -99,6 +115,10 @@ async function load() {
|
||||
console.log(`Worker ${worker.process.pid} ${worker.id} is online`);
|
||||
});
|
||||
await startWorker(cnt);
|
||||
} else if (argv.entry) {
|
||||
console.log(`Worker ${process.pid} Starting as ${argv.entry}`);
|
||||
await entry({ entry: argv.entry });
|
||||
console.log(`Worker ${process.pid} Started as ${argv.entry}`);
|
||||
} else {
|
||||
console.log(`Worker ${process.pid} Starting`);
|
||||
await entry({ entry: 'worker' });
|
||||
|
||||
Reference in new issue
Block a user