aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/schedulers/remove-old-history-scheduler.ts
blob: 1b5ff83944b51e44ead9bd1600617d56faeef4c5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { logger } from '../../helpers/logger'
import { AbstractScheduler } from './abstract-scheduler'
import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants'
import { UserVideoHistoryModel } from '../../models/account/user-video-history'
import { CONFIG } from '../../initializers/config'
import { isTestInstance } from '../../helpers/core-utils'

export class RemoveOldHistoryScheduler extends AbstractScheduler {

  private static instance: AbstractScheduler

  protected schedulerIntervalMs = SCHEDULER_INTERVALS_MS.removeOldHistory

  private constructor () {
    super()
  }

  protected internalExecute () {
    if (CONFIG.HISTORY.VIDEOS.MAX_AGE === -1) return

    logger.info('Removing old videos history.')

    const now = new Date()
    const beforeDate = new Date(now.getTime() - CONFIG.HISTORY.VIDEOS.MAX_AGE).toISOString()

    return UserVideoHistoryModel.removeOldHistory(beforeDate)
  }

  static get Instance () {
    return this.instance || (this.instance = new this())
  }
}