2022-03-24 07:36:47 -05:00
|
|
|
import { VideoViewModel } from '@server/models/view/video-view'
|
2019-04-11 10:33:36 -05:00
|
|
|
import { logger } from '../../helpers/logger'
|
|
|
|
import { CONFIG } from '../../initializers/config'
|
2022-03-24 07:36:47 -05:00
|
|
|
import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants'
|
|
|
|
import { AbstractScheduler } from './abstract-scheduler'
|
2019-04-11 10:33:36 -05:00
|
|
|
|
|
|
|
export class RemoveOldViewsScheduler extends AbstractScheduler {
|
|
|
|
|
|
|
|
private static instance: AbstractScheduler
|
|
|
|
|
2021-10-22 03:28:00 -05:00
|
|
|
protected schedulerIntervalMs = SCHEDULER_INTERVALS_MS.REMOVE_OLD_VIEWS
|
2019-04-11 10:33:36 -05:00
|
|
|
|
|
|
|
private constructor () {
|
|
|
|
super()
|
|
|
|
}
|
|
|
|
|
|
|
|
protected internalExecute () {
|
|
|
|
if (CONFIG.VIEWS.VIDEOS.REMOTE.MAX_AGE === -1) return
|
|
|
|
|
|
|
|
logger.info('Removing old videos views.')
|
|
|
|
|
|
|
|
const now = new Date()
|
|
|
|
const beforeDate = new Date(now.getTime() - CONFIG.VIEWS.VIDEOS.REMOTE.MAX_AGE).toISOString()
|
|
|
|
|
|
|
|
return VideoViewModel.removeOldRemoteViewsHistory(beforeDate)
|
|
|
|
}
|
|
|
|
|
|
|
|
static get Instance () {
|
|
|
|
return this.instance || (this.instance = new this())
|
|
|
|
}
|
|
|
|
}
|