aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/schedulers/remove-old-views-scheduler.ts
blob: 5ae87fe5045356f06222e2c54dbcc29869717c0c (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
import { logger } from '../../helpers/logger'
import { AbstractScheduler } from './abstract-scheduler'
import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants'
import { CONFIG } from '../../initializers/config'
import { VideoViewModel } from '../../models/video/video-views'

export class RemoveOldViewsScheduler extends AbstractScheduler {

  private static instance: AbstractScheduler

  protected schedulerIntervalMs = SCHEDULER_INTERVALS_MS.removeOldViews

  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())
  }
}