enhance(server): separate job queue process (#9662)
* enhance(server): separate job queue process * add commands for build with swc
This commit is contained in:
parent
0b4a7e8166
commit
7e89e70934
@ -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 {}
|
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -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) {
|
||||
|
@ -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: [
|
||||
|
Loading…
Reference in New Issue
Block a user