fix(backend): ServerStatsService start within running app
This commit is contained in:
parent
4fdf5e6add
commit
573af1b9ba
|
|
@ -4,6 +4,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
|
import { ServerStatsService } from '../daemons/ServerStatsService.js';
|
||||||
import { AccountMoveService } from './AccountMoveService.js';
|
import { AccountMoveService } from './AccountMoveService.js';
|
||||||
import { AccountUpdateService } from './AccountUpdateService.js';
|
import { AccountUpdateService } from './AccountUpdateService.js';
|
||||||
import { AiService } from './AiService.js';
|
import { AiService } from './AiService.js';
|
||||||
|
|
@ -248,6 +249,8 @@ const $ApMentionService: Provider = { provide: 'ApMentionService', useExisting:
|
||||||
const $ApNoteService: Provider = { provide: 'ApNoteService', useExisting: ApNoteService };
|
const $ApNoteService: Provider = { provide: 'ApNoteService', useExisting: ApNoteService };
|
||||||
const $ApPersonService: Provider = { provide: 'ApPersonService', useExisting: ApPersonService };
|
const $ApPersonService: Provider = { provide: 'ApPersonService', useExisting: ApPersonService };
|
||||||
const $ApQuestionService: Provider = { provide: 'ApQuestionService', useExisting: ApQuestionService };
|
const $ApQuestionService: Provider = { provide: 'ApQuestionService', useExisting: ApQuestionService };
|
||||||
|
|
||||||
|
const $ServerStatsService: Provider = { provide: 'ServerStatsService', useExisting: ServerStatsService };
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
|
|
@ -374,6 +377,7 @@ const $ApQuestionService: Provider = { provide: 'ApQuestionService', useExisting
|
||||||
ApPersonService,
|
ApPersonService,
|
||||||
ApQuestionService,
|
ApQuestionService,
|
||||||
QueueService,
|
QueueService,
|
||||||
|
ServerStatsService,
|
||||||
|
|
||||||
//#region 文字列ベースでのinjection用(循環参照対応のため)
|
//#region 文字列ベースでのinjection用(循環参照対応のため)
|
||||||
$LoggerService,
|
$LoggerService,
|
||||||
|
|
@ -494,6 +498,7 @@ const $ApQuestionService: Provider = { provide: 'ApQuestionService', useExisting
|
||||||
$ApNoteService,
|
$ApNoteService,
|
||||||
$ApPersonService,
|
$ApPersonService,
|
||||||
$ApQuestionService,
|
$ApQuestionService,
|
||||||
|
$ServerStatsService,
|
||||||
//#endregion
|
//#endregion
|
||||||
],
|
],
|
||||||
exports: [
|
exports: [
|
||||||
|
|
@ -616,6 +621,7 @@ const $ApQuestionService: Provider = { provide: 'ApQuestionService', useExisting
|
||||||
ApPersonService,
|
ApPersonService,
|
||||||
ApQuestionService,
|
ApQuestionService,
|
||||||
QueueService,
|
QueueService,
|
||||||
|
ServerStatsService,
|
||||||
|
|
||||||
//#region 文字列ベースでのinjection用(循環参照対応のため)
|
//#region 文字列ベースでのinjection用(循環参照対応のため)
|
||||||
$LoggerService,
|
$LoggerService,
|
||||||
|
|
@ -735,6 +741,7 @@ const $ApQuestionService: Provider = { provide: 'ApQuestionService', useExisting
|
||||||
$ApNoteService,
|
$ApNoteService,
|
||||||
$ApPersonService,
|
$ApPersonService,
|
||||||
$ApQuestionService,
|
$ApQuestionService,
|
||||||
|
$ServerStatsService,
|
||||||
//#endregion
|
//#endregion
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -6,19 +6,24 @@
|
||||||
import { Inject, Injectable } from '@nestjs/common';
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
import { DataSource } from 'typeorm';
|
import { DataSource } from 'typeorm';
|
||||||
import * as Redis from 'ioredis';
|
import * as Redis from 'ioredis';
|
||||||
|
import { ModuleRef } from '@nestjs/core';
|
||||||
import { DI } from '@/di-symbols.js';
|
import { DI } from '@/di-symbols.js';
|
||||||
import { MiMeta } from '@/models/entities/Meta.js';
|
import { MiMeta } from '@/models/entities/Meta.js';
|
||||||
import { GlobalEventService } from '@/core/GlobalEventService.js';
|
import { GlobalEventService } from '@/core/GlobalEventService.js';
|
||||||
|
import { ServerStatsService } from '@/daemons/ServerStatsService.js';
|
||||||
import { bindThis } from '@/decorators.js';
|
import { bindThis } from '@/decorators.js';
|
||||||
import { StreamMessages } from '@/server/api/stream/types.js';
|
import { StreamMessages } from '@/server/api/stream/types.js';
|
||||||
import type { OnApplicationShutdown } from '@nestjs/common';
|
import type { OnApplicationShutdown } from '@nestjs/common';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class MetaService implements OnApplicationShutdown {
|
export class MetaService implements OnApplicationShutdown {
|
||||||
|
private serverStatsService: ServerStatsService;
|
||||||
private cache: MiMeta | undefined;
|
private cache: MiMeta | undefined;
|
||||||
private intervalId: NodeJS.Timeout;
|
private intervalId: NodeJS.Timeout;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
private moduleRef: ModuleRef,
|
||||||
|
|
||||||
@Inject(DI.redisForSub)
|
@Inject(DI.redisForSub)
|
||||||
private redisForSub: Redis.Redis,
|
private redisForSub: Redis.Redis,
|
||||||
|
|
||||||
|
|
@ -41,6 +46,10 @@ export class MetaService implements OnApplicationShutdown {
|
||||||
this.redisForSub.on('message', this.onMessage);
|
this.redisForSub.on('message', this.onMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onModuleInit() {
|
||||||
|
this.serverStatsService = this.moduleRef.get('ServerStatsService');
|
||||||
|
}
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
private async onMessage(_: string, data: string): Promise<void> {
|
private async onMessage(_: string, data: string): Promise<void> {
|
||||||
const obj = JSON.parse(data);
|
const obj = JSON.parse(data);
|
||||||
|
|
@ -121,6 +130,12 @@ export class MetaService implements OnApplicationShutdown {
|
||||||
|
|
||||||
this.globalEventService.publishInternalEvent('metaUpdated', updated);
|
this.globalEventService.publishInternalEvent('metaUpdated', updated);
|
||||||
|
|
||||||
|
if (updated.enableServerMachineStats === true) {
|
||||||
|
await this.serverStatsService.start();
|
||||||
|
} else {
|
||||||
|
this.serverStatsService.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
return updated;
|
return updated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,9 @@ export class ServerStatsService implements OnApplicationShutdown {
|
||||||
const log = [] as any[];
|
const log = [] as any[];
|
||||||
|
|
||||||
ev.on('requestServerStatsLog', x => {
|
ev.on('requestServerStatsLog', x => {
|
||||||
|
// skip when service deactivated
|
||||||
|
if (this.intervalId === null) return;
|
||||||
|
|
||||||
ev.emit(`serverStatsLog:${x.id}`, log.slice(0, x.length ?? 50));
|
ev.emit(`serverStatsLog:${x.id}`, log.slice(0, x.length ?? 50));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue