remove-old-history-scheduler.ts 952 B

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