convert ApLogsCleanupService into a queue task
This commit is contained in:
parent
edcaef0727
commit
7050583b86
6 changed files with 51 additions and 71 deletions
|
|
@ -124,7 +124,7 @@ export class QueueService implements OnModuleInit {
|
|||
|
||||
await this.systemQueue.upsertJobScheduler(
|
||||
'clean-scheduler',
|
||||
{ pattern: '15 1 * * *' },
|
||||
{ pattern: '10 1 * * *' },
|
||||
{
|
||||
name: 'clean',
|
||||
opts: {
|
||||
|
|
@ -144,9 +144,20 @@ export class QueueService implements OnModuleInit {
|
|||
},
|
||||
});
|
||||
|
||||
await this.systemQueue.upsertJobScheduler(
|
||||
'cleanupApLogs-scheduler',
|
||||
{ pattern: '*/10 * * *' },
|
||||
{
|
||||
name: 'cleanupApLogs',
|
||||
opts: {
|
||||
removeOnComplete: 10,
|
||||
removeOnFail: 30,
|
||||
},
|
||||
});
|
||||
|
||||
await this.systemQueue.upsertJobScheduler(
|
||||
'backBufferedReactions-scheduler',
|
||||
{ pattern: '30 1 * * *' },
|
||||
{ pattern: '20 1 * * *' },
|
||||
{
|
||||
name: 'backBufferedReactions',
|
||||
opts: {
|
||||
|
|
@ -158,7 +169,7 @@ export class QueueService implements OnModuleInit {
|
|||
await this.systemQueue.upsertJobScheduler(
|
||||
'checkModeratorsActivity-scheduler',
|
||||
// 毎時30分に起動
|
||||
{ pattern: '45 1 * * *' },
|
||||
{ pattern: '30 1 * * *' },
|
||||
{
|
||||
name: 'checkModeratorsActivity',
|
||||
opts: {
|
||||
|
|
|
|||
|
|
@ -1,65 +0,0 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: hazelnoot and other Sharkey contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
import { Injectable, type OnApplicationShutdown } from '@nestjs/common';
|
||||
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 '@/global/TimeService.js';
|
||||
|
||||
// 10 minutes
|
||||
export const scanInterval = 1000 * 60 * 10;
|
||||
|
||||
@Injectable()
|
||||
export class ApLogCleanupService implements OnApplicationShutdown {
|
||||
private readonly logger: Logger;
|
||||
private scanTimer: TimerHandle | null = null;
|
||||
|
||||
constructor(
|
||||
private readonly apLogService: ApLogService,
|
||||
private readonly timeService: TimeService,
|
||||
|
||||
loggerService: LoggerService,
|
||||
) {
|
||||
this.logger = loggerService.getLogger('activity-log-cleanup');
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async start(): Promise<void> {
|
||||
// Just in case start() gets called multiple times.
|
||||
this.dispose();
|
||||
|
||||
// Prune at startup, in case the server was rebooted during the interval.
|
||||
// noinspection ES6MissingAwait
|
||||
this.tick();
|
||||
|
||||
// Prune on a regular interval for the lifetime of the server.
|
||||
this.scanTimer = this.timeService.startTimer(this.tick, scanInterval, { repeated: true });
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async tick(): Promise<void> {
|
||||
try {
|
||||
const affected = await this.apLogService.deleteExpiredLogs();
|
||||
this.logger.info(`Activity Log cleanup complete; removed ${affected} expired logs.`);
|
||||
} catch (err) {
|
||||
this.logger.error('Activity Log cleanup failed:', err as Error);
|
||||
}
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public onApplicationShutdown(): void {
|
||||
this.dispose();
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public dispose(): void {
|
||||
if (this.scanTimer) {
|
||||
this.timeService.stopTimer(this.scanTimer);
|
||||
this.scanTimer = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -7,7 +7,6 @@ import { Module } from '@nestjs/common';
|
|||
import { CoreModule } from '@/core/CoreModule.js';
|
||||
import { QueueStatsService } from './QueueStatsService.js';
|
||||
import { ServerStatsService } from './ServerStatsService.js';
|
||||
import { ApLogCleanupService } from './ApLogCleanupService.js';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
|
|
@ -16,12 +15,10 @@ import { ApLogCleanupService } from './ApLogCleanupService.js';
|
|||
providers: [
|
||||
QueueStatsService,
|
||||
ServerStatsService,
|
||||
ApLogCleanupService,
|
||||
],
|
||||
exports: [
|
||||
QueueStatsService,
|
||||
ServerStatsService,
|
||||
ApLogCleanupService,
|
||||
],
|
||||
})
|
||||
export class DaemonModule {}
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ import { AggregateRetentionProcessorService } from './processors/AggregateRetent
|
|||
import { ExportFavoritesProcessorService } from './processors/ExportFavoritesProcessorService.js';
|
||||
import { RelationshipProcessorService } from './processors/RelationshipProcessorService.js';
|
||||
import { ScheduleNotePostProcessorService } from './processors/ScheduleNotePostProcessorService.js';
|
||||
import { CleanupApLogsProcessorService } from './processors/CleanupApLogsProcessorService.js';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
|
|
@ -89,6 +90,7 @@ import { ScheduleNotePostProcessorService } from './processors/ScheduleNotePostP
|
|||
CheckModeratorsActivityProcessorService,
|
||||
QueueProcessorService,
|
||||
ScheduleNotePostProcessorService,
|
||||
CleanupApLogsProcessorService,
|
||||
],
|
||||
exports: [
|
||||
QueueProcessorService,
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ import { ScheduleNotePostProcessorService } from './processors/ScheduleNotePostP
|
|||
import { QueueLoggerService } from './QueueLoggerService.js';
|
||||
import { QUEUE, baseWorkerOptions } from './const.js';
|
||||
import { ImportNotesProcessorService } from './processors/ImportNotesProcessorService.js';
|
||||
import { CleanupApLogsProcessorService } from './processors/CleanupApLogsProcessorService.js';
|
||||
|
||||
// ref. https://github.com/misskey-dev/misskey/pull/7635#issue-971097019
|
||||
function httpRelatedBackoff(attemptsMade: number) {
|
||||
|
|
@ -136,6 +137,7 @@ export class QueueProcessorService implements OnApplicationShutdown {
|
|||
private cleanProcessorService: CleanProcessorService,
|
||||
private scheduleNotePostProcessorService: ScheduleNotePostProcessorService,
|
||||
private readonly timeService: TimeService,
|
||||
private readonly cleanupApLogsProcessorService: CleanupApLogsProcessorService,
|
||||
) {
|
||||
this.logger = this.queueLoggerService.logger;
|
||||
|
||||
|
|
@ -156,6 +158,7 @@ export class QueueProcessorService implements OnApplicationShutdown {
|
|||
case 'bakeBufferedReactions': return this.bakeBufferedReactionsProcessorService.process();
|
||||
case 'checkModeratorsActivity': return this.checkModeratorsActivityProcessorService.process();
|
||||
case 'clean': return this.cleanProcessorService.process();
|
||||
case 'cleanupApLogs': return this.cleanupApLogsProcessorService.process();
|
||||
default: throw new Error(`unrecognized job type ${job.name} for system`);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: hazelnoot and other Sharkey contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
import { QueueLoggerService } from '@/queue/QueueLoggerService.js';
|
||||
import Logger from '@/logger.js';
|
||||
import { ApLogService } from '@/core/ApLogService.js';
|
||||
|
||||
@Injectable()
|
||||
export class CleanupApLogsProcessorService {
|
||||
private readonly logger: Logger;
|
||||
|
||||
constructor(
|
||||
private readonly apLogService: ApLogService,
|
||||
queueLoggerService: QueueLoggerService,
|
||||
) {
|
||||
this.logger = queueLoggerService.logger.createSubLogger('activity-log-cleanup');
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async process(): Promise<void> {
|
||||
try {
|
||||
const affected = await this.apLogService.deleteExpiredLogs();
|
||||
this.logger.info(`Activity Log cleanup complete; removed ${affected} expired logs.`);
|
||||
} catch (err) {
|
||||
this.logger.error('Activity Log cleanup failed:', err as Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue