Skip to content

Commit

Permalink
fix(backend): ServerStatsService start within running app
Browse files Browse the repository at this point in the history
  • Loading branch information
ZerglingGo committed Jul 21, 2023
1 parent 7097d55 commit a4d2c54
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/backend/src/server/api/EndpointsModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down Expand Up @@ -695,6 +696,7 @@ const $retention: Provider = { provide: 'ep:retention', useClass: ep___retention
providers: [
GetterService,
ApiLoggerService,
ServerStatsService,
$admin_meta,
$admin_abuseUserReports,
$admin_accounts_create,
Expand Down
12 changes: 12 additions & 0 deletions packages/backend/src/server/api/endpoints/admin/update-meta.ts
Original file line number Diff line number Diff line change
@@ -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'],
Expand Down Expand Up @@ -109,6 +111,8 @@ export const paramDef = {
@Injectable()
export default class extends Endpoint<typeof meta, typeof paramDef> {
constructor(
private moduleRef: ModuleRef,

@Inject(DI.db)
private db: DataSource,

Expand Down Expand Up @@ -424,6 +428,14 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {

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();
}
});
}
}

0 comments on commit a4d2c54

Please sign in to comment.