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 { Module } from '@nestjs/common';
|
||||||
import { ServerModule } from '@/server/ServerModule.js';
|
import { ServerModule } from '@/server/ServerModule.js';
|
||||||
import { GlobalModule } from '@/GlobalModule.js';
|
import { GlobalModule } from '@/GlobalModule.js';
|
||||||
import { QueueProcessorModule } from '@/queue/QueueProcessorModule.js';
|
import { DaemonModule } from '@/daemons/DaemonModule.js';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
GlobalModule,
|
GlobalModule,
|
||||||
ServerModule,
|
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 { QueueStatsService } from '@/daemons/QueueStatsService.js';
|
||||||
import { ServerStatsService } from '@/daemons/ServerStatsService.js';
|
import { ServerStatsService } from '@/daemons/ServerStatsService.js';
|
||||||
import { NestLogger } from '@/NestLogger.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';
|
import { envOption } from '../env.js';
|
||||||
|
|
||||||
const _filename = fileURLToPath(import.meta.url);
|
const _filename = fileURLToPath(import.meta.url);
|
||||||
|
@ -70,6 +73,15 @@ export async function masterMain() {
|
||||||
process.exit(1);
|
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');
|
bootLogger.succ('Misskey initialized');
|
||||||
|
|
||||||
if (!envOption.disableClustering) {
|
if (!envOption.disableClustering) {
|
||||||
|
@ -78,15 +90,10 @@ 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);
|
||||||
|
|
||||||
if (!envOption.noDaemons) {
|
app.get(ChartManagementService).start();
|
||||||
const daemons = await NestFactory.createApplicationContext(DaemonModule, {
|
app.get(JanitorService).start();
|
||||||
logger: new NestLogger(),
|
app.get(QueueStatsService).start();
|
||||||
});
|
app.get(ServerStatsService).start();
|
||||||
daemons.enableShutdownHooks();
|
|
||||||
daemons.get(JanitorService).start();
|
|
||||||
daemons.get(QueueStatsService).start();
|
|
||||||
daemons.get(ServerStatsService).start();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function showEnvironment(): void {
|
function showEnvironment(): void {
|
||||||
|
|
|
@ -1,32 +1,23 @@
|
||||||
import cluster from 'node:cluster';
|
import cluster from 'node:cluster';
|
||||||
import { NestFactory } from '@nestjs/core';
|
import { NestFactory } from '@nestjs/core';
|
||||||
import { envOption } from '@/env.js';
|
|
||||||
import { ChartManagementService } from '@/core/chart/ChartManagementService.js';
|
import { ChartManagementService } from '@/core/chart/ChartManagementService.js';
|
||||||
import { ServerService } from '@/server/ServerService.js';
|
|
||||||
import { QueueProcessorService } from '@/queue/QueueProcessorService.js';
|
import { QueueProcessorService } from '@/queue/QueueProcessorService.js';
|
||||||
import { NestLogger } from '@/NestLogger.js';
|
import { NestLogger } from '@/NestLogger.js';
|
||||||
import { RootModule } from '../RootModule.js';
|
import { QueueProcessorModule } from '@/queue/QueueProcessorModule.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Init worker process
|
* Init worker process
|
||||||
*/
|
*/
|
||||||
export async function workerMain() {
|
export async function workerMain() {
|
||||||
const app = await NestFactory.createApplicationContext(RootModule, {
|
const jobQueue = await NestFactory.createApplicationContext(QueueProcessorModule, {
|
||||||
logger: new NestLogger(),
|
logger: new NestLogger(),
|
||||||
});
|
});
|
||||||
app.enableShutdownHooks();
|
jobQueue.enableShutdownHooks();
|
||||||
|
|
||||||
// start server
|
|
||||||
const serverService = app.get(ServerService);
|
|
||||||
serverService.launch();
|
|
||||||
|
|
||||||
// start job queue
|
// start job queue
|
||||||
if (!envOption.onlyServer) {
|
jobQueue.get(QueueProcessorService).start();
|
||||||
const queueProcessorService = app.get(QueueProcessorService);
|
|
||||||
queueProcessorService.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
app.get(ChartManagementService).run();
|
jobQueue.get(ChartManagementService).start();
|
||||||
|
|
||||||
if (cluster.isWorker) {
|
if (cluster.isWorker) {
|
||||||
// Send a 'ready' message to parent process
|
// Send a 'ready' message to parent process
|
||||||
|
|
|
@ -54,7 +54,7 @@ export class ChartManagementService implements OnApplicationShutdown {
|
||||||
}
|
}
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
public async run() {
|
public async start() {
|
||||||
// 20分おきにメモリ情報をDBに書き込み
|
// 20分おきにメモリ情報をDBに書き込み
|
||||||
this.saveIntervalId = setInterval(() => {
|
this.saveIntervalId = setInterval(() => {
|
||||||
for (const chart of this.charts) {
|
for (const chart of this.charts) {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
import { CoreModule } from '@/core/CoreModule.js';
|
import { CoreModule } from '@/core/CoreModule.js';
|
||||||
|
import { GlobalModule } from '@/GlobalModule.js';
|
||||||
import { QueueLoggerService } from './QueueLoggerService.js';
|
import { QueueLoggerService } from './QueueLoggerService.js';
|
||||||
import { QueueProcessorService } from './QueueProcessorService.js';
|
import { QueueProcessorService } from './QueueProcessorService.js';
|
||||||
import { DbQueueProcessorsService } from './DbQueueProcessorsService.js';
|
import { DbQueueProcessorsService } from './DbQueueProcessorsService.js';
|
||||||
|
@ -34,6 +35,7 @@ import { ExportFavoritesProcessorService } from './processors/ExportFavoritesPro
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
|
GlobalModule,
|
||||||
CoreModule,
|
CoreModule,
|
||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
|
|
Loading…
Reference in New Issue