]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/schedulers/remove-old-history-scheduler.ts
Merge branch 'release/5.0.0' into develop
[github/Chocobozzz/PeerTube.git] / server / lib / schedulers / remove-old-history-scheduler.ts
CommitLineData
8f0bc73d
C
1import { logger } from '../../helpers/logger'
2import { AbstractScheduler } from './abstract-scheduler'
3import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants'
7d9ba5c0 4import { UserVideoHistoryModel } from '../../models/user/user-video-history'
8f0bc73d 5import { CONFIG } from '../../initializers/config'
8f0bc73d
C
6
7export class RemoveOldHistoryScheduler extends AbstractScheduler {
8
9 private static instance: AbstractScheduler
10
61953742 11 protected schedulerIntervalMs = SCHEDULER_INTERVALS_MS.REMOVE_OLD_HISTORY
8f0bc73d
C
12
13 private constructor () {
14 super()
15 }
16
17 protected internalExecute () {
18 if (CONFIG.HISTORY.VIDEOS.MAX_AGE === -1) return
19
20 logger.info('Removing old videos history.')
21
22 const now = new Date()
23 const beforeDate = new Date(now.getTime() - CONFIG.HISTORY.VIDEOS.MAX_AGE).toISOString()
24
25 return UserVideoHistoryModel.removeOldHistory(beforeDate)
26 }
27
28 static get Instance () {
29 return this.instance || (this.instance = new this())
30 }
31}