diff options
Diffstat (limited to 'server/lib/schedulers/remove-old-views-scheduler.ts')
-rw-r--r-- | server/lib/schedulers/remove-old-views-scheduler.ts | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/server/lib/schedulers/remove-old-views-scheduler.ts b/server/lib/schedulers/remove-old-views-scheduler.ts new file mode 100644 index 000000000..39fbb9163 --- /dev/null +++ b/server/lib/schedulers/remove-old-views-scheduler.ts | |||
@@ -0,0 +1,33 @@ | |||
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 | import { VideoViewModel } from '../../models/video/video-views' | ||
8 | |||
9 | export class RemoveOldViewsScheduler extends AbstractScheduler { | ||
10 | |||
11 | private static instance: AbstractScheduler | ||
12 | |||
13 | protected schedulerIntervalMs = SCHEDULER_INTERVALS_MS.removeOldViews | ||
14 | |||
15 | private constructor () { | ||
16 | super() | ||
17 | } | ||
18 | |||
19 | protected internalExecute () { | ||
20 | if (CONFIG.VIEWS.VIDEOS.REMOTE.MAX_AGE === -1) return | ||
21 | |||
22 | logger.info('Removing old videos views.') | ||
23 | |||
24 | const now = new Date() | ||
25 | const beforeDate = new Date(now.getTime() - CONFIG.VIEWS.VIDEOS.REMOTE.MAX_AGE).toISOString() | ||
26 | |||
27 | return VideoViewModel.removeOldRemoteViewsHistory(beforeDate) | ||
28 | } | ||
29 | |||
30 | static get Instance () { | ||
31 | return this.instance || (this.instance = new this()) | ||
32 | } | ||
33 | } | ||