From 8f0bc73d7d5f4c88cbc5588a0ece12b3855c8f98 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 11 Apr 2019 15:38:53 +0200 Subject: Add ability to limit videos history size --- server/lib/schedulers/abstract-scheduler.ts | 3 +- .../lib/schedulers/remove-old-history-scheduler.ts | 32 ++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 server/lib/schedulers/remove-old-history-scheduler.ts (limited to 'server/lib/schedulers') diff --git a/server/lib/schedulers/abstract-scheduler.ts b/server/lib/schedulers/abstract-scheduler.ts index 86ea7aa38..0e6088911 100644 --- a/server/lib/schedulers/abstract-scheduler.ts +++ b/server/lib/schedulers/abstract-scheduler.ts @@ -1,4 +1,5 @@ import { logger } from '../../helpers/logger' +import * as Bluebird from 'bluebird' export abstract class AbstractScheduler { @@ -30,5 +31,5 @@ export abstract class AbstractScheduler { } } - protected abstract internalExecute (): Promise + protected abstract internalExecute (): Promise | Bluebird } diff --git a/server/lib/schedulers/remove-old-history-scheduler.ts b/server/lib/schedulers/remove-old-history-scheduler.ts new file mode 100644 index 000000000..1b5ff8394 --- /dev/null +++ b/server/lib/schedulers/remove-old-history-scheduler.ts @@ -0,0 +1,32 @@ +import { logger } from '../../helpers/logger' +import { AbstractScheduler } from './abstract-scheduler' +import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants' +import { UserVideoHistoryModel } from '../../models/account/user-video-history' +import { CONFIG } from '../../initializers/config' +import { isTestInstance } from '../../helpers/core-utils' + +export class RemoveOldHistoryScheduler extends AbstractScheduler { + + private static instance: AbstractScheduler + + protected schedulerIntervalMs = SCHEDULER_INTERVALS_MS.removeOldHistory + + private constructor () { + super() + } + + protected internalExecute () { + if (CONFIG.HISTORY.VIDEOS.MAX_AGE === -1) return + + logger.info('Removing old videos history.') + + 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()) + } +} -- cgit v1.2.3