Wrap entry into async function
This commit is contained in:
parent
3d15f89638
commit
447399eb07
1 changed files with 49 additions and 46 deletions
|
@ -27,60 +27,63 @@ const logger = new Logger('core', 'cyan');
|
||||||
const clusterLogger = logger.createSubLogger('cluster', 'orange', false);
|
const clusterLogger = logger.createSubLogger('cluster', 'orange', false);
|
||||||
const ev = new Xev();
|
const ev = new Xev();
|
||||||
|
|
||||||
//#region Events
|
// We wrap this in a main function, that gets called,
|
||||||
|
// because not all platforms support top level await :/
|
||||||
|
|
||||||
// Listen new workers
|
async function main() {
|
||||||
cluster.on('fork', worker => {
|
//#region Events
|
||||||
|
// Listen new workers
|
||||||
|
cluster.on('fork', worker => {
|
||||||
clusterLogger.debug(`Process forked: [${worker.id}]`);
|
clusterLogger.debug(`Process forked: [${worker.id}]`);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Listen online workers
|
// Listen online workers
|
||||||
cluster.on('online', worker => {
|
cluster.on('online', worker => {
|
||||||
clusterLogger.debug(`Process is now online: [${worker.id}]`);
|
clusterLogger.debug(`Process is now online: [${worker.id}]`);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Listen for dying workers
|
// Listen for dying workers
|
||||||
cluster.on('exit', worker => {
|
cluster.on('exit', worker => {
|
||||||
// Replace the dead worker,
|
// Replace the dead worker,
|
||||||
// we're not sentimental
|
// we're not sentimental
|
||||||
clusterLogger.error(chalk.red(`[${worker.id}] died :(`));
|
clusterLogger.error(chalk.red(`[${worker.id}] died :(`));
|
||||||
cluster.fork();
|
cluster.fork();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Display detail of unhandled promise rejection
|
// Display detail of unhandled promise rejection
|
||||||
if (!envOption.quiet) {
|
if (!envOption.quiet) {
|
||||||
process.on('unhandledRejection', console.dir);
|
process.on('unhandledRejection', console.dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Display detail of uncaught exception
|
// Display detail of uncaught exception
|
||||||
process.on('uncaughtException', err => {
|
process.on('uncaughtException', err => {
|
||||||
try {
|
try {
|
||||||
logger.error(err);
|
logger.error(err);
|
||||||
console.trace(err);
|
console.trace(err);
|
||||||
} catch { }
|
} catch { }
|
||||||
});
|
});
|
||||||
|
|
||||||
// Dying away...
|
// Dying away...
|
||||||
process.on('exit', code => {
|
process.on('exit', code => {
|
||||||
logger.info(`The process is going to exit with code ${code}`);
|
logger.info(`The process is going to exit with code ${code}`);
|
||||||
});
|
});
|
||||||
|
//#endregion
|
||||||
|
|
||||||
//#endregion
|
if (cluster.isPrimary || envOption.disableClustering) {
|
||||||
|
|
||||||
if (cluster.isPrimary || envOption.disableClustering) {
|
|
||||||
await masterMain();
|
await masterMain();
|
||||||
|
|
||||||
if (cluster.isPrimary) {
|
if (cluster.isPrimary) {
|
||||||
ev.mount();
|
ev.mount();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (cluster.isWorker || envOption.disableClustering) {
|
||||||
if (cluster.isWorker || envOption.disableClustering) {
|
|
||||||
await workerMain();
|
await workerMain();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ユニットテスト時にMisskeyが子プロセスで起動された時のため
|
||||||
|
// それ以外のときは process.send は使えないので弾く
|
||||||
|
if (process.send) {
|
||||||
|
process.send('ok');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ユニットテスト時にMisskeyが子プロセスで起動された時のため
|
main();
|
||||||
// それ以外のときは process.send は使えないので弾く
|
|
||||||
if (process.send) {
|
|
||||||
process.send('ok');
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue