1 import { logger } from '../../helpers/logger'
2 import { AbstractScheduler } from './abstract-scheduler'
3 import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants'
4 import { UserVideoHistoryModel } from '../../models/user/user-video-history'
5 import { CONFIG } from '../../initializers/config'
7 export class RemoveOldHistoryScheduler extends AbstractScheduler {
9 private static instance: AbstractScheduler
11 protected schedulerIntervalMs = SCHEDULER_INTERVALS_MS.removeOldHistory
13 private constructor () {
17 protected internalExecute () {
18 if (CONFIG.HISTORY.VIDEOS.MAX_AGE === -1) return
20 logger.info('Removing old videos history.')
22 const now = new Date()
23 const beforeDate = new Date(now.getTime() - CONFIG.HISTORY.VIDEOS.MAX_AGE).toISOString()
25 return UserVideoHistoryModel.removeOldHistory(beforeDate)
28 static get Instance () {
29 return this.instance || (this.instance = new this())