enhance(server): onlyServer / onlyQueue オプションを復活

This commit is contained in:
syuilo 2023-01-23 20:07:48 +09:00
parent 7028b7331b
commit 7b73dd2d62
3 changed files with 53 additions and 38 deletions

View file

@ -0,0 +1,35 @@
import { NestFactory } from '@nestjs/core';
import { ChartManagementService } from '@/core/chart/ChartManagementService.js';
import { QueueProcessorService } from '@/queue/QueueProcessorService.js';
import { NestLogger } from '@/NestLogger.js';
import { QueueProcessorModule } from '@/queue/QueueProcessorModule.js';
import { JanitorService } from '@/daemons/JanitorService.js';
import { QueueStatsService } from '@/daemons/QueueStatsService.js';
import { ServerStatsService } from '@/daemons/ServerStatsService.js';
import { ServerService } from '@/server/ServerService.js';
import { MainModule } from '@/MainModule.js';
export async function server() {
const app = await NestFactory.createApplicationContext(MainModule, {
logger: new NestLogger(),
});
app.enableShutdownHooks();
const serverService = app.get(ServerService);
serverService.launch();
app.get(ChartManagementService).start();
app.get(JanitorService).start();
app.get(QueueStatsService).start();
app.get(ServerStatsService).start();
}
export async function jobQueue() {
const jobQueue = await NestFactory.createApplicationContext(QueueProcessorModule, {
logger: new NestLogger(),
});
jobQueue.enableShutdownHooks();
jobQueue.get(QueueProcessorService).start();
jobQueue.get(ChartManagementService).start();
}

View file

@ -6,21 +6,12 @@ import cluster from 'node:cluster';
import chalk from 'chalk'; import chalk from 'chalk';
import chalkTemplate from 'chalk-template'; import chalkTemplate from 'chalk-template';
import semver from 'semver'; import semver from 'semver';
import { NestFactory } from '@nestjs/core';
import Logger from '@/logger.js'; import Logger from '@/logger.js';
import { loadConfig } from '@/config.js'; import { loadConfig } from '@/config.js';
import type { Config } from '@/config.js'; import type { Config } from '@/config.js';
import { lessThan } from '@/misc/prelude/array.js';
import { showMachineInfo } from '@/misc/show-machine-info.js'; import { showMachineInfo } from '@/misc/show-machine-info.js';
import { DaemonModule } from '@/daemons/DaemonModule.js'; import { envOption } from '@/env.js';
import { JanitorService } from '@/daemons/JanitorService.js'; import { jobQueue, server } from './common.js';
import { QueueStatsService } from '@/daemons/QueueStatsService.js';
import { ServerStatsService } from '@/daemons/ServerStatsService.js';
import { NestLogger } from '@/NestLogger.js';
import { ChartManagementService } from '@/core/chart/ChartManagementService.js';
import { ServerService } from '@/server/ServerService.js';
import { MainModule } from '@/MainModule.js';
import { envOption } from '../env.js';
const _filename = fileURLToPath(import.meta.url); const _filename = fileURLToPath(import.meta.url);
const _dirname = dirname(_filename); const _dirname = dirname(_filename);
@ -73,14 +64,13 @@ export async function masterMain() {
process.exit(1); process.exit(1);
} }
const app = await NestFactory.createApplicationContext(MainModule, { if (envOption.onlyServer) {
logger: new NestLogger(), await server();
}); } else if (envOption.onlyQueue) {
app.enableShutdownHooks(); await jobQueue();
} else {
// start server await server();
const serverService = app.get(ServerService); }
serverService.launch();
bootLogger.succ('Misskey initialized'); bootLogger.succ('Misskey initialized');
@ -89,11 +79,6 @@ export async function masterMain() {
} }
bootLogger.succ(`Now listening on port ${config.port} on ${config.url}`, null, true); bootLogger.succ(`Now listening on port ${config.port} on ${config.url}`, null, true);
app.get(ChartManagementService).start();
app.get(JanitorService).start();
app.get(QueueStatsService).start();
app.get(ServerStatsService).start();
} }
function showEnvironment(): void { function showEnvironment(): void {

View file

@ -1,23 +1,18 @@
import cluster from 'node:cluster'; import cluster from 'node:cluster';
import { NestFactory } from '@nestjs/core'; import { envOption } from '@/env.js';
import { ChartManagementService } from '@/core/chart/ChartManagementService.js'; import { jobQueue, server } from './common.js';
import { QueueProcessorService } from '@/queue/QueueProcessorService.js';
import { NestLogger } from '@/NestLogger.js';
import { QueueProcessorModule } from '@/queue/QueueProcessorModule.js';
/** /**
* Init worker process * Init worker process
*/ */
export async function workerMain() { export async function workerMain() {
const jobQueue = await NestFactory.createApplicationContext(QueueProcessorModule, { if (envOption.onlyServer) {
logger: new NestLogger(), await server();
}); } else if (envOption.onlyQueue) {
jobQueue.enableShutdownHooks(); await jobQueue();
} else {
// start job queue await jobQueue();
jobQueue.get(QueueProcessorService).start(); }
jobQueue.get(ChartManagementService).start();
if (cluster.isWorker) { if (cluster.isWorker) {
// Send a 'ready' message to parent process // Send a 'ready' message to parent process