diff options
| author | April John <30842467+CutestNekoAqua@users.noreply.github.com> | 2023-10-07 16:21:09 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-07 16:21:09 +0200 |
| commit | 447399eb078db97647e421edec1bfcb02ea6d6c4 (patch) | |
| tree | 6e91707a89baedc2d824b8ac2dba5708a72cb1b7 /packages/backend/src/boot | |
| parent | Change pkg command (diff) | |
| download | sharkey-447399eb078db97647e421edec1bfcb02ea6d6c4.tar.gz sharkey-447399eb078db97647e421edec1bfcb02ea6d6c4.tar.bz2 sharkey-447399eb078db97647e421edec1bfcb02ea6d6c4.zip | |
Wrap entry into async function
Diffstat (limited to 'packages/backend/src/boot')
| -rw-r--r-- | packages/backend/src/boot/entry.ts | 95 |
1 files changed, 49 insertions, 46 deletions
diff --git a/packages/backend/src/boot/entry.ts b/packages/backend/src/boot/entry.ts index fc8fc2ffb4..bd0ed29fc2 100644 --- a/packages/backend/src/boot/entry.ts +++ b/packages/backend/src/boot/entry.ts @@ -27,60 +27,63 @@ const logger = new Logger('core', 'cyan'); const clusterLogger = logger.createSubLogger('cluster', 'orange', false); 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 -cluster.on('fork', worker => { - clusterLogger.debug(`Process forked: [${worker.id}]`); -}); +async function main() { + //#region Events + // Listen new workers + cluster.on('fork', worker => { + clusterLogger.debug(`Process forked: [${worker.id}]`); + }); -// Listen online workers -cluster.on('online', worker => { - clusterLogger.debug(`Process is now online: [${worker.id}]`); -}); + // Listen online workers + cluster.on('online', worker => { + clusterLogger.debug(`Process is now online: [${worker.id}]`); + }); -// Listen for dying workers -cluster.on('exit', worker => { - // Replace the dead worker, - // we're not sentimental - clusterLogger.error(chalk.red(`[${worker.id}] died :(`)); - cluster.fork(); -}); + // Listen for dying workers + cluster.on('exit', worker => { + // Replace the dead worker, + // we're not sentimental + clusterLogger.error(chalk.red(`[${worker.id}] died :(`)); + cluster.fork(); + }); -// Display detail of unhandled promise rejection -if (!envOption.quiet) { - process.on('unhandledRejection', console.dir); -} - -// Display detail of uncaught exception -process.on('uncaughtException', err => { - try { - logger.error(err); - console.trace(err); - } catch { } -}); - -// Dying away... -process.on('exit', code => { - logger.info(`The process is going to exit with code ${code}`); -}); + // Display detail of unhandled promise rejection + if (!envOption.quiet) { + process.on('unhandledRejection', console.dir); + } -//#endregion + // Display detail of uncaught exception + process.on('uncaughtException', err => { + try { + logger.error(err); + console.trace(err); + } catch { } + }); -if (cluster.isPrimary || envOption.disableClustering) { - await masterMain(); + // Dying away... + process.on('exit', code => { + logger.info(`The process is going to exit with code ${code}`); + }); + //#endregion - if (cluster.isPrimary) { - ev.mount(); + if (cluster.isPrimary || envOption.disableClustering) { + await masterMain(); + if (cluster.isPrimary) { + ev.mount(); + } + } + if (cluster.isWorker || envOption.disableClustering) { + await workerMain(); } -} -if (cluster.isWorker || envOption.disableClustering) { - await workerMain(); + // ユニットテスト時にMisskeyが子プロセスで起動された時のため + // それ以外のときは process.send は使えないので弾く + if (process.send) { + process.send('ok'); + } } -// ユニットテスト時にMisskeyが子プロセスで起動された時のため -// それ以外のときは process.send は使えないので弾く -if (process.send) { - process.send('ok'); -} +main(); |