use TimeService everywhere in the backend
This commit is contained in:
parent
ed750fd990
commit
6cceca90f9
123 changed files with 550 additions and 285 deletions
|
|
@ -8,6 +8,7 @@ import { bindThis } from '@/decorators.js';
|
|||
import { LoggerService } from '@/core/LoggerService.js';
|
||||
import Logger from '@/logger.js';
|
||||
import { ApLogService } from '@/core/ApLogService.js';
|
||||
import { TimeService, type TimerHandle } from '@/core/TimeService.js';
|
||||
|
||||
// 10 minutes
|
||||
export const scanInterval = 1000 * 60 * 10;
|
||||
|
|
@ -15,10 +16,12 @@ export const scanInterval = 1000 * 60 * 10;
|
|||
@Injectable()
|
||||
export class ApLogCleanupService implements OnApplicationShutdown {
|
||||
private readonly logger: Logger;
|
||||
private scanTimer: NodeJS.Timeout | null = null;
|
||||
private scanTimer: TimerHandle | null = null;
|
||||
|
||||
constructor(
|
||||
private readonly apLogService: ApLogService,
|
||||
private readonly timeService: TimeService,
|
||||
|
||||
loggerService: LoggerService,
|
||||
) {
|
||||
this.logger = loggerService.getLogger('activity-log-cleanup');
|
||||
|
|
@ -34,7 +37,7 @@ export class ApLogCleanupService implements OnApplicationShutdown {
|
|||
this.tick();
|
||||
|
||||
// Prune on a regular interval for the lifetime of the server.
|
||||
this.scanTimer = setInterval(this.tick, scanInterval);
|
||||
this.scanTimer = this.timeService.startTimer(this.tick, scanInterval, { repeated: true });
|
||||
}
|
||||
|
||||
@bindThis
|
||||
|
|
@ -55,7 +58,7 @@ export class ApLogCleanupService implements OnApplicationShutdown {
|
|||
@bindThis
|
||||
public dispose(): void {
|
||||
if (this.scanTimer) {
|
||||
clearInterval(this.scanTimer);
|
||||
this.timeService.stopTimer(this.scanTimer);
|
||||
this.scanTimer = null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import { Inject, Injectable } from '@nestjs/common';
|
|||
import Xev from 'xev';
|
||||
import * as Bull from 'bullmq';
|
||||
import { QueueService } from '@/core/QueueService.js';
|
||||
import { TimeService, type TimerHandle } from '@/core/TimeService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import type { Config } from '@/config.js';
|
||||
|
|
@ -31,7 +32,7 @@ const interval = 10000;
|
|||
|
||||
@Injectable()
|
||||
export class QueueStatsService implements OnApplicationShutdown {
|
||||
private intervalId?: NodeJS.Timeout;
|
||||
private intervalId?: TimerHandle;
|
||||
private activeDeliverJobs = 0;
|
||||
private activeInboxJobs = 0;
|
||||
|
||||
|
|
@ -45,6 +46,7 @@ export class QueueStatsService implements OnApplicationShutdown {
|
|||
private config: Config,
|
||||
|
||||
private queueService: QueueService,
|
||||
private readonly timeService: TimeService,
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
@ -114,13 +116,13 @@ export class QueueStatsService implements OnApplicationShutdown {
|
|||
|
||||
tick();
|
||||
|
||||
this.intervalId = setInterval(tick, interval);
|
||||
this.intervalId = this.timeService.startTimer(tick, interval, { repeated: true });
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async stop() {
|
||||
if (this.intervalId) {
|
||||
clearInterval(this.intervalId);
|
||||
this.timeService.stopTimer(this.intervalId);
|
||||
}
|
||||
|
||||
this.log = undefined;
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import { bindThis } from '@/decorators.js';
|
|||
import type { OnApplicationShutdown } from '@nestjs/common';
|
||||
import { MiMeta } from '@/models/_.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import { TimeService, type TimerHandle } from '@/core/TimeService.js';
|
||||
|
||||
export interface Stats {
|
||||
cpu: number,
|
||||
|
|
@ -37,13 +38,14 @@ const round = (num: number) => Math.round(num * 10) / 10;
|
|||
|
||||
@Injectable()
|
||||
export class ServerStatsService implements OnApplicationShutdown {
|
||||
private intervalId: NodeJS.Timeout | null = null;
|
||||
private intervalId: TimerHandle | null = null;
|
||||
|
||||
private log: Stats[] = [];
|
||||
|
||||
constructor(
|
||||
@Inject(DI.meta)
|
||||
private meta: MiMeta,
|
||||
private readonly timeService: TimeService,
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
@ -90,13 +92,13 @@ export class ServerStatsService implements OnApplicationShutdown {
|
|||
|
||||
tick();
|
||||
|
||||
this.intervalId = setInterval(tick, interval);
|
||||
this.intervalId = this.timeService.startTimer(tick, interval, { repeated: true });
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public dispose(): void {
|
||||
if (this.intervalId) {
|
||||
clearInterval(this.intervalId);
|
||||
this.timeService.stopTimer(this.intervalId);
|
||||
}
|
||||
|
||||
this.log = [];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue