2
1

remove-old-views-scheduler.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233
  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/account/user-video-history'
  5. import { CONFIG } from '../../initializers/config'
  6. import { isTestInstance } from '../../helpers/core-utils'
  7. import { VideoViewModel } from '../../models/video/video-views'
  8. export class RemoveOldViewsScheduler extends AbstractScheduler {
  9. private static instance: AbstractScheduler
  10. protected schedulerIntervalMs = SCHEDULER_INTERVALS_MS.removeOldViews
  11. private constructor () {
  12. super()
  13. }
  14. protected internalExecute () {
  15. if (CONFIG.VIEWS.VIDEOS.REMOTE.MAX_AGE === -1) return
  16. logger.info('Removing old videos views.')
  17. const now = new Date()
  18. const beforeDate = new Date(now.getTime() - CONFIG.VIEWS.VIDEOS.REMOTE.MAX_AGE).toISOString()
  19. return VideoViewModel.removeOldRemoteViewsHistory(beforeDate)
  20. }
  21. static get Instance () {
  22. return this.instance || (this.instance = new this())
  23. }
  24. }