1
0
Fork 0
peertube/server/lib/schedulers/remove-old-views-scheduler.ts
Chocobozzz b211106695 Support video views/viewers stats in server
* Add "currentTime" and "event" body params to view endpoint
 * Merge watching and view endpoints
 * Introduce WatchAction AP activity
 * Add tables to store viewer information of local videos
 * Add endpoints to fetch video views/viewers stats of local videos
 * Refactor views/viewers handlers
 * Support "views" and "viewers" counters for both VOD and live videos
2022-04-15 09:49:35 +02:00

31 lines
946 B
TypeScript

import { VideoViewModel } from '@server/models/view/video-view'
import { logger } from '../../helpers/logger'
import { CONFIG } from '../../initializers/config'
import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants'
import { AbstractScheduler } from './abstract-scheduler'
export class RemoveOldViewsScheduler extends AbstractScheduler {
private static instance: AbstractScheduler
protected schedulerIntervalMs = SCHEDULER_INTERVALS_MS.REMOVE_OLD_VIEWS
private constructor () {
super()
}
protected internalExecute () {
if (CONFIG.VIEWS.VIDEOS.REMOTE.MAX_AGE === -1) return
logger.info('Removing old videos views.')
const now = new Date()
const beforeDate = new Date(now.getTime() - CONFIG.VIEWS.VIDEOS.REMOTE.MAX_AGE).toISOString()
return VideoViewModel.removeOldRemoteViewsHistory(beforeDate)
}
static get Instance () {
return this.instance || (this.instance = new this())
}
}