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