1f7a81aae7
* update deps
* node16
* wip
* wip
* wip
* Update test-utils.ts
* wip
* Update tsconfig.json
* wip
* Update package.json
* wip
* Update following.vue
* Update followers.vue
* Update index.vue
* Update share.vue
* Update MkUserPopup.vue
* Update MkPostForm.vue
* wip
* Update MkTokenGenerateWindow.vue
* Update MkPagination.vue
* refactor
* update deps
* update deps
* Update sw.ts
* wip
* wip
* wip
* Update FetchInstanceMetadataService.ts
* Update FetchInstanceMetadataService.ts
* update node
* update deps
* 🎨
83 lines
2.4 KiB
TypeScript
83 lines
2.4 KiB
TypeScript
/*
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
import { Injectable } from '@nestjs/common';
|
|
|
|
import { bindThis } from '@/decorators.js';
|
|
import FederationChart from './charts/federation.js';
|
|
import NotesChart from './charts/notes.js';
|
|
import UsersChart from './charts/users.js';
|
|
import ActiveUsersChart from './charts/active-users.js';
|
|
import InstanceChart from './charts/instance.js';
|
|
import PerUserNotesChart from './charts/per-user-notes.js';
|
|
import PerUserPvChart from './charts/per-user-pv.js';
|
|
import DriveChart from './charts/drive.js';
|
|
import PerUserReactionsChart from './charts/per-user-reactions.js';
|
|
import PerUserFollowingChart from './charts/per-user-following.js';
|
|
import PerUserDriveChart from './charts/per-user-drive.js';
|
|
import ApRequestChart from './charts/ap-request.js';
|
|
import type { OnApplicationShutdown } from '@nestjs/common';
|
|
|
|
@Injectable()
|
|
export class ChartManagementService implements OnApplicationShutdown {
|
|
private charts;
|
|
private saveIntervalId: NodeJS.Timeout;
|
|
|
|
constructor(
|
|
private federationChart: FederationChart,
|
|
private notesChart: NotesChart,
|
|
private usersChart: UsersChart,
|
|
private activeUsersChart: ActiveUsersChart,
|
|
private instanceChart: InstanceChart,
|
|
private perUserNotesChart: PerUserNotesChart,
|
|
private perUserPvChart: PerUserPvChart,
|
|
private driveChart: DriveChart,
|
|
private perUserReactionsChart: PerUserReactionsChart,
|
|
private perUserFollowingChart: PerUserFollowingChart,
|
|
private perUserDriveChart: PerUserDriveChart,
|
|
private apRequestChart: ApRequestChart,
|
|
) {
|
|
this.charts = [
|
|
this.federationChart,
|
|
this.notesChart,
|
|
this.usersChart,
|
|
this.activeUsersChart,
|
|
this.instanceChart,
|
|
this.perUserNotesChart,
|
|
this.perUserPvChart,
|
|
this.driveChart,
|
|
this.perUserReactionsChart,
|
|
this.perUserFollowingChart,
|
|
this.perUserDriveChart,
|
|
this.apRequestChart,
|
|
];
|
|
}
|
|
|
|
@bindThis
|
|
public async start() {
|
|
// 20分おきにメモリ情報をDBに書き込み
|
|
this.saveIntervalId = setInterval(() => {
|
|
for (const chart of this.charts) {
|
|
chart.save();
|
|
}
|
|
}, 1000 * 60 * 20);
|
|
}
|
|
|
|
@bindThis
|
|
public async dispose(): Promise<void> {
|
|
clearInterval(this.saveIntervalId);
|
|
if (process.env.NODE_ENV !== 'test') {
|
|
await Promise.all(
|
|
this.charts.map(chart => chart.save()),
|
|
);
|
|
}
|
|
}
|
|
|
|
@bindThis
|
|
async onApplicationShutdown(signal: string): Promise<void> {
|
|
await this.dispose();
|
|
}
|
|
}
|