remove-old-views-scheduler.ts 943 B

12345678910111213141516171819202122232425262728293031
  1. import { logger } from '../../helpers/logger'
  2. import { AbstractScheduler } from './abstract-scheduler'
  3. import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants'
  4. import { CONFIG } from '../../initializers/config'
  5. import { VideoViewModel } from '../../models/video/video-view'
  6. export class RemoveOldViewsScheduler extends AbstractScheduler {
  7. private static instance: AbstractScheduler
  8. protected schedulerIntervalMs = SCHEDULER_INTERVALS_MS.removeOldViews
  9. private constructor () {
  10. super()
  11. }
  12. protected internalExecute () {
  13. if (CONFIG.VIEWS.VIDEOS.REMOTE.MAX_AGE === -1) return
  14. logger.info('Removing old videos views.')
  15. const now = new Date()
  16. const beforeDate = new Date(now.getTime() - CONFIG.VIEWS.VIDEOS.REMOTE.MAX_AGE).toISOString()
  17. return VideoViewModel.removeOldRemoteViewsHistory(beforeDate)
  18. }
  19. static get Instance () {
  20. return this.instance || (this.instance = new this())
  21. }
  22. }