remove-old-history-scheduler.ts 1010 B

1234567891011121314151617181920212223242526272829303132
  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. export class RemoveOldHistoryScheduler extends AbstractScheduler {
  8. private static instance: AbstractScheduler
  9. protected schedulerIntervalMs = SCHEDULER_INTERVALS_MS.removeOldHistory
  10. private constructor () {
  11. super()
  12. }
  13. protected internalExecute () {
  14. if (CONFIG.HISTORY.VIDEOS.MAX_AGE === -1) return
  15. logger.info('Removing old videos history.')
  16. const now = new Date()
  17. const beforeDate = new Date(now.getTime() - CONFIG.HISTORY.VIDEOS.MAX_AGE).toISOString()
  18. return UserVideoHistoryModel.removeOldHistory(beforeDate)
  19. }
  20. static get Instance () {
  21. return this.instance || (this.instance = new this())
  22. }
  23. }