Init commit
This commit is contained in:
32
server/core/lib/schedulers/remove-old-history-scheduler.ts
Normal file
32
server/core/lib/schedulers/remove-old-history-scheduler.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { logger, loggerTagsFactory } from '../../helpers/logger.js'
|
||||
import { CONFIG } from '../../initializers/config.js'
|
||||
import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants.js'
|
||||
import { UserVideoHistoryModel } from '../../models/user/user-video-history.js'
|
||||
import { AbstractScheduler } from './abstract-scheduler.js'
|
||||
|
||||
const lTags = loggerTagsFactory('schedulers')
|
||||
|
||||
export class RemoveOldHistoryScheduler extends AbstractScheduler {
|
||||
private static instance: AbstractScheduler
|
||||
|
||||
protected schedulerIntervalMs = SCHEDULER_INTERVALS_MS.REMOVE_OLD_HISTORY
|
||||
|
||||
private constructor () {
|
||||
super({ randomRunOnEnable: true })
|
||||
}
|
||||
|
||||
protected internalExecute () {
|
||||
if (CONFIG.HISTORY.VIDEOS.MAX_AGE === -1) return
|
||||
|
||||
logger.info('Removing old videos history.', lTags())
|
||||
|
||||
const now = new Date()
|
||||
const beforeDate = new Date(now.getTime() - CONFIG.HISTORY.VIDEOS.MAX_AGE).toISOString()
|
||||
|
||||
return UserVideoHistoryModel.removeOldHistory(beforeDate)
|
||||
}
|
||||
|
||||
static get Instance () {
|
||||
return this.instance || (this.instance = new this())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user