mirror of
https://github.com/misskey-dev/misskey
synced 2024-11-27 22:38:39 +09:00
refactor(backend): simplify boot
This commit is contained in:
parent
0abecffa8b
commit
a66111ac1f
@ -10,8 +10,8 @@
|
||||
"scripts": {
|
||||
"postinstall": "node ./scripts/install-packages.js",
|
||||
"build": "node ./scripts/build.js",
|
||||
"start": "cd packages/backend && node --experimental-json-modules ./built/index.js",
|
||||
"start:test": "cd packages/backend && cross-env NODE_ENV=test node --experimental-json-modules ./built/index.js",
|
||||
"start": "cd packages/backend && node --experimental-json-modules ./built/boot/index.js",
|
||||
"start:test": "cd packages/backend && cross-env NODE_ENV=test node --experimental-json-modules ./built/boot/index.js",
|
||||
"init": "npm run migrate",
|
||||
"migrate": "cd packages/backend && npx typeorm migration:run -d ormconfig.js",
|
||||
"migrateandstart": "npm run migrate && npm run start",
|
||||
|
@ -1,44 +1,28 @@
|
||||
|
||||
/**
|
||||
* Misskey Entry Point!
|
||||
*/
|
||||
|
||||
import cluster from 'node:cluster';
|
||||
import { EventEmitter } from 'node:events';
|
||||
import chalk from 'chalk';
|
||||
import Xev from 'xev';
|
||||
|
||||
import Logger from '@/logger.js';
|
||||
import { envOption } from '../env.js';
|
||||
|
||||
// for typeorm
|
||||
import 'reflect-metadata';
|
||||
import { masterMain } from './master.js';
|
||||
import { workerMain } from './worker.js';
|
||||
|
||||
import 'reflect-metadata';
|
||||
|
||||
process.title = `Misskey (${cluster.isPrimary ? 'master' : 'worker'})`;
|
||||
|
||||
Error.stackTraceLimit = Infinity;
|
||||
EventEmitter.defaultMaxListeners = 128;
|
||||
|
||||
const logger = new Logger('core', 'cyan');
|
||||
const clusterLogger = logger.createSubLogger('cluster', 'orange', false);
|
||||
const ev = new Xev();
|
||||
|
||||
/**
|
||||
* Init process
|
||||
*/
|
||||
export default async function() {
|
||||
process.title = `Misskey (${cluster.isPrimary ? 'master' : 'worker'})`;
|
||||
|
||||
if (cluster.isPrimary || envOption.disableClustering) {
|
||||
await masterMain();
|
||||
|
||||
if (cluster.isPrimary) {
|
||||
ev.mount();
|
||||
}
|
||||
}
|
||||
|
||||
if (cluster.isWorker || envOption.disableClustering) {
|
||||
await workerMain();
|
||||
}
|
||||
|
||||
// ユニットテスト時にMisskeyが子プロセスで起動された時のため
|
||||
// それ以外のときは process.send は使えないので弾く
|
||||
if (process.send) {
|
||||
process.send('ok');
|
||||
}
|
||||
}
|
||||
|
||||
//#region Events
|
||||
|
||||
// Listen new workers
|
||||
@ -77,3 +61,21 @@ process.on('exit', code => {
|
||||
});
|
||||
|
||||
//#endregion
|
||||
|
||||
if (cluster.isPrimary || envOption.disableClustering) {
|
||||
await masterMain();
|
||||
|
||||
if (cluster.isPrimary) {
|
||||
ev.mount();
|
||||
}
|
||||
}
|
||||
|
||||
if (cluster.isWorker || envOption.disableClustering) {
|
||||
await workerMain();
|
||||
}
|
||||
|
||||
// ユニットテスト時にMisskeyが子プロセスで起動された時のため
|
||||
// それ以外のときは process.send は使えないので弾く
|
||||
if (process.send) {
|
||||
process.send('ok');
|
||||
}
|
||||
|
@ -1,13 +0,0 @@
|
||||
/**
|
||||
* Misskey Entry Point!
|
||||
*/
|
||||
|
||||
import { EventEmitter } from 'node:events';
|
||||
import boot from './boot/index.js';
|
||||
|
||||
Error.stackTraceLimit = Infinity;
|
||||
EventEmitter.defaultMaxListeners = 128;
|
||||
|
||||
boot().catch(err => {
|
||||
console.error(err);
|
||||
});
|
@ -10,7 +10,7 @@
|
||||
"declaration": false,
|
||||
"sourceMap": false,
|
||||
"target": "es2021",
|
||||
"module": "es2020",
|
||||
"module": "es2022",
|
||||
"moduleResolution": "node",
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"removeComments": false,
|
||||
|
Loading…
Reference in New Issue
Block a user