summaryrefslogtreecommitdiff
path: root/packages/backend/src/daemons/ApLogCleanupService.ts
diff options
context:
space:
mode:
authorHazelnoot <acomputerdog@gmail.com>2025-01-30 22:36:19 -0500
committerHazelnoot <acomputerdog@gmail.com>2025-02-16 19:25:22 -0500
commit81944b3bdf49cf95294adcefc265a568b921dee0 (patch)
tree3693a235357d9d9576b694128e03a065d36921b9 /packages/backend/src/daemons/ApLogCleanupService.ts
parentrename activity_log and activity_context to ap_inbox_log and ap_context (diff)
downloadsharkey-81944b3bdf49cf95294adcefc265a568b921dee0.tar.gz
sharkey-81944b3bdf49cf95294adcefc265a568b921dee0.tar.bz2
sharkey-81944b3bdf49cf95294adcefc265a568b921dee0.zip
implement AP fetch logs
Diffstat (limited to 'packages/backend/src/daemons/ApLogCleanupService.ts')
-rw-r--r--packages/backend/src/daemons/ApLogCleanupService.ts29
1 files changed, 9 insertions, 20 deletions
diff --git a/packages/backend/src/daemons/ApLogCleanupService.ts b/packages/backend/src/daemons/ApLogCleanupService.ts
index 261c6e3517..2b6693e19e 100644
--- a/packages/backend/src/daemons/ApLogCleanupService.ts
+++ b/packages/backend/src/daemons/ApLogCleanupService.ts
@@ -3,14 +3,11 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
-import { Inject, Injectable, type OnApplicationShutdown } from '@nestjs/common';
-import { LessThan } from 'typeorm';
-import { DI } from '@/di-symbols.js';
-import type { Config } from '@/config.js';
+import { Injectable, type OnApplicationShutdown } from '@nestjs/common';
import { bindThis } from '@/decorators.js';
-import type { ApInboxLogsRepository } from '@/models/_.js';
import { LoggerService } from '@/core/LoggerService.js';
import Logger from '@/logger.js';
+import { ApLogService } from '@/core/ApLogService.js';
// 10 minutes
export const scanInterval = 1000 * 60 * 10;
@@ -21,12 +18,7 @@ export class ApLogCleanupService implements OnApplicationShutdown {
private scanTimer: NodeJS.Timeout | null = null;
constructor(
- @Inject(DI.config)
- private readonly config: Config,
-
- @Inject(DI.apInboxLogsRepository)
- private readonly apInboxLogsRepository: ApInboxLogsRepository,
-
+ private readonly apLogService: ApLogService,
loggerService: LoggerService,
) {
this.logger = loggerService.getLogger('activity-log-cleanup');
@@ -47,15 +39,12 @@ export class ApLogCleanupService implements OnApplicationShutdown {
@bindThis
private async tick(): Promise<void> {
- // This is the date in UTC of the oldest log to KEEP
- const oldestAllowed = new Date(Date.now() - this.config.activityLogging.maxAge);
-
- // Delete all logs older than the threshold.
- const { affected } = await this.apInboxLogsRepository.delete({
- at: LessThan(oldestAllowed),
- });
-
- this.logger.info(`Activity Log cleanup complete; removed ${affected ?? 0} expired logs.`);
+ try {
+ const affected = 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