2022-09-17 18:27:08 +00:00
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
|
|
|
import { In, LessThan, MoreThan } from 'typeorm';
|
|
|
|
import { DI } from '@/di-symbols.js';
|
2022-12-21 23:17:13 +00:00
|
|
|
import type { NotificationsRepository, UserIpsRepository } from '@/models/index.js';
|
2022-09-20 20:33:11 +00:00
|
|
|
import type { Config } from '@/config.js';
|
2022-09-17 18:27:08 +00:00
|
|
|
import type Logger from '@/logger.js';
|
2022-12-21 23:17:13 +00:00
|
|
|
import { bindThis } from '@/decorators.js';
|
2022-09-17 18:27:08 +00:00
|
|
|
import { QueueLoggerService } from '../QueueLoggerService.js';
|
|
|
|
import type Bull from 'bull';
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class CleanProcessorService {
|
2022-09-18 18:11:50 +00:00
|
|
|
private logger: Logger;
|
2022-09-17 18:27:08 +00:00
|
|
|
|
|
|
|
constructor(
|
|
|
|
@Inject(DI.config)
|
|
|
|
private config: Config,
|
|
|
|
|
|
|
|
@Inject(DI.userIpsRepository)
|
|
|
|
private userIpsRepository: UserIpsRepository,
|
|
|
|
|
2022-12-21 23:17:13 +00:00
|
|
|
@Inject(DI.notificationsRepository)
|
|
|
|
private notificationsRepository: NotificationsRepository,
|
|
|
|
|
2022-09-17 18:27:08 +00:00
|
|
|
private queueLoggerService: QueueLoggerService,
|
|
|
|
) {
|
2022-09-18 18:11:50 +00:00
|
|
|
this.logger = this.queueLoggerService.logger.createSubLogger('clean');
|
2022-09-17 18:27:08 +00:00
|
|
|
}
|
|
|
|
|
2022-12-04 06:03:09 +00:00
|
|
|
@bindThis
|
2022-09-17 18:27:08 +00:00
|
|
|
public async process(job: Bull.Job<Record<string, unknown>>, done: () => void): Promise<void> {
|
2022-09-18 18:11:50 +00:00
|
|
|
this.logger.info('Cleaning...');
|
2022-09-17 18:27:08 +00:00
|
|
|
|
|
|
|
this.userIpsRepository.delete({
|
|
|
|
createdAt: LessThan(new Date(Date.now() - (1000 * 60 * 60 * 24 * 90))),
|
|
|
|
});
|
|
|
|
|
2022-12-21 23:17:13 +00:00
|
|
|
this.notificationsRepository.delete({
|
|
|
|
createdAt: LessThan(new Date(Date.now() - (1000 * 60 * 60 * 24 * 90))),
|
|
|
|
});
|
|
|
|
|
2022-09-18 18:11:50 +00:00
|
|
|
this.logger.succ('Cleaned.');
|
2022-09-17 18:27:08 +00:00
|
|
|
done();
|
|
|
|
}
|
|
|
|
}
|