diff --git a/packages/backend/src/RootModule.ts b/packages/backend/src/MainModule.ts similarity index 63% rename from packages/backend/src/RootModule.ts rename to packages/backend/src/MainModule.ts index 3fc392776..fc568e883 100644 --- a/packages/backend/src/RootModule.ts +++ b/packages/backend/src/MainModule.ts @@ -1,13 +1,13 @@ import { Module } from '@nestjs/common'; import { ServerModule } from '@/server/ServerModule.js'; import { GlobalModule } from '@/GlobalModule.js'; -import { QueueProcessorModule } from '@/queue/QueueProcessorModule.js'; +import { DaemonModule } from '@/daemons/DaemonModule.js'; @Module({ imports: [ GlobalModule, ServerModule, - QueueProcessorModule, + DaemonModule, ], }) -export class RootModule {} +export class MainModule {} diff --git a/packages/backend/src/boot/master.ts b/packages/backend/src/boot/master.ts index 4630217c4..93cb3131b 100644 --- a/packages/backend/src/boot/master.ts +++ b/packages/backend/src/boot/master.ts @@ -17,6 +17,9 @@ import { JanitorService } from '@/daemons/JanitorService.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); @@ -70,6 +73,15 @@ export async function masterMain() { process.exit(1); } + const app = await NestFactory.createApplicationContext(MainModule, { + logger: new NestLogger(), + }); + app.enableShutdownHooks(); + + // start server + const serverService = app.get(ServerService); + serverService.launch(); + bootLogger.succ('Misskey initialized'); if (!envOption.disableClustering) { @@ -78,15 +90,10 @@ export async function masterMain() { bootLogger.succ(`Now listening on port ${config.port} on ${config.url}`, null, true); - if (!envOption.noDaemons) { - const daemons = await NestFactory.createApplicationContext(DaemonModule, { - logger: new NestLogger(), - }); - daemons.enableShutdownHooks(); - daemons.get(JanitorService).start(); - daemons.get(QueueStatsService).start(); - daemons.get(ServerStatsService).start(); - } + app.get(ChartManagementService).start(); + app.get(JanitorService).start(); + app.get(QueueStatsService).start(); + app.get(ServerStatsService).start(); } function showEnvironment(): void { diff --git a/packages/backend/src/boot/worker.ts b/packages/backend/src/boot/worker.ts index f29e37de7..e0574643b 100644 --- a/packages/backend/src/boot/worker.ts +++ b/packages/backend/src/boot/worker.ts @@ -1,32 +1,23 @@ import cluster from 'node:cluster'; import { NestFactory } from '@nestjs/core'; -import { envOption } from '@/env.js'; import { ChartManagementService } from '@/core/chart/ChartManagementService.js'; -import { ServerService } from '@/server/ServerService.js'; import { QueueProcessorService } from '@/queue/QueueProcessorService.js'; import { NestLogger } from '@/NestLogger.js'; -import { RootModule } from '../RootModule.js'; +import { QueueProcessorModule } from '@/queue/QueueProcessorModule.js'; /** * Init worker process */ export async function workerMain() { - const app = await NestFactory.createApplicationContext(RootModule, { + const jobQueue = await NestFactory.createApplicationContext(QueueProcessorModule, { logger: new NestLogger(), }); - app.enableShutdownHooks(); - - // start server - const serverService = app.get(ServerService); - serverService.launch(); + jobQueue.enableShutdownHooks(); // start job queue - if (!envOption.onlyServer) { - const queueProcessorService = app.get(QueueProcessorService); - queueProcessorService.start(); - } + jobQueue.get(QueueProcessorService).start(); - app.get(ChartManagementService).run(); + jobQueue.get(ChartManagementService).start(); if (cluster.isWorker) { // Send a 'ready' message to parent process diff --git a/packages/backend/src/core/chart/ChartManagementService.ts b/packages/backend/src/core/chart/ChartManagementService.ts index 37de30b71..4fba1b57d 100644 --- a/packages/backend/src/core/chart/ChartManagementService.ts +++ b/packages/backend/src/core/chart/ChartManagementService.ts @@ -54,7 +54,7 @@ export class ChartManagementService implements OnApplicationShutdown { } @bindThis - public async run() { + public async start() { // 20分おきにメモリ情報をDBに書き込み this.saveIntervalId = setInterval(() => { for (const chart of this.charts) { diff --git a/packages/backend/src/queue/QueueProcessorModule.ts b/packages/backend/src/queue/QueueProcessorModule.ts index 034e9cc5a..6a8f35cdd 100644 --- a/packages/backend/src/queue/QueueProcessorModule.ts +++ b/packages/backend/src/queue/QueueProcessorModule.ts @@ -1,5 +1,6 @@ import { Module } from '@nestjs/common'; import { CoreModule } from '@/core/CoreModule.js'; +import { GlobalModule } from '@/GlobalModule.js'; import { QueueLoggerService } from './QueueLoggerService.js'; import { QueueProcessorService } from './QueueProcessorService.js'; import { DbQueueProcessorsService } from './DbQueueProcessorsService.js'; @@ -34,6 +35,7 @@ import { ExportFavoritesProcessorService } from './processors/ExportFavoritesPro @Module({ imports: [ + GlobalModule, CoreModule, ], providers: [