From a4d2c54bf2e86eceb8915b7c095b9a8f0ca4909c Mon Sep 17 00:00:00 2001 From: ZerglingGo Date: Sat, 22 Jul 2023 04:02:41 +0900 Subject: [PATCH] fix(backend): ServerStatsService start within running app --- packages/backend/src/server/api/EndpointsModule.ts | 2 ++ .../src/server/api/endpoints/admin/update-meta.ts | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/packages/backend/src/server/api/EndpointsModule.ts b/packages/backend/src/server/api/EndpointsModule.ts index 4e6bc46e67..44e9a684b1 100644 --- a/packages/backend/src/server/api/EndpointsModule.ts +++ b/packages/backend/src/server/api/EndpointsModule.ts @@ -344,6 +344,7 @@ import * as ep___fetchRss from './endpoints/fetch-rss.js'; import * as ep___retention from './endpoints/retention.js'; import { GetterService } from './GetterService.js'; import { ApiLoggerService } from './ApiLoggerService.js'; +import { ServerStatsService } from '@/daemons/ServerStatsService.js'; import type { Provider } from '@nestjs/common'; const $admin_meta: Provider = { provide: 'ep:admin/meta', useClass: ep___admin_meta.default }; @@ -695,6 +696,7 @@ const $retention: Provider = { provide: 'ep:retention', useClass: ep___retention providers: [ GetterService, ApiLoggerService, + ServerStatsService, $admin_meta, $admin_abuseUserReports, $admin_accounts_create, diff --git a/packages/backend/src/server/api/endpoints/admin/update-meta.ts b/packages/backend/src/server/api/endpoints/admin/update-meta.ts index 144360a921..b29a4e8398 100644 --- a/packages/backend/src/server/api/endpoints/admin/update-meta.ts +++ b/packages/backend/src/server/api/endpoints/admin/update-meta.ts @@ -1,10 +1,12 @@ import { Inject, Injectable } from '@nestjs/common'; +import { ModuleRef } from '@nestjs/core'; import { DataSource } from 'typeorm'; import type { Meta } from '@/models/entities/Meta.js'; import { ModerationLogService } from '@/core/ModerationLogService.js'; import { Endpoint } from '@/server/api/endpoint-base.js'; import { DI } from '@/di-symbols.js'; import { MetaService } from '@/core/MetaService.js'; +import { ServerStatsService } from '@/daemons/ServerStatsService.js'; export const meta = { tags: ['admin'], @@ -109,6 +111,8 @@ export const paramDef = { @Injectable() export default class extends Endpoint { constructor( + private moduleRef: ModuleRef, + @Inject(DI.db) private db: DataSource, @@ -424,6 +428,14 @@ export default class extends Endpoint { await this.metaService.update(set); this.moderationLogService.insertModerationLog(me, 'updateMeta'); + + if (set.enableServerMachineStats === true) { + const serverStatsService: ServerStatsService = await this.moduleRef.resolve(ServerStatsService); + await serverStatsService.start(); + } else { + const serverStatsService: ServerStatsService = await this.moduleRef.resolve(ServerStatsService); + serverStatsService.dispose(); + } }); } }