aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-04-11 15:38:53 +0200
committerChocobozzz <me@florianbigard.com>2019-04-11 15:38:53 +0200
commit8f0bc73d7d5f4c88cbc5588a0ece12b3855c8f98 (patch)
treee04f1da52f9377cf6ce820425c0de6e57ab57fc6 /server/lib
parent76062d9f96e06a23a2efc8a727ea9c5394d21466 (diff)
downloadPeerTube-8f0bc73d7d5f4c88cbc5588a0ece12b3855c8f98.tar.gz
PeerTube-8f0bc73d7d5f4c88cbc5588a0ece12b3855c8f98.tar.zst
PeerTube-8f0bc73d7d5f4c88cbc5588a0ece12b3855c8f98.zip
Add ability to limit videos history size
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/schedulers/abstract-scheduler.ts3
-rw-r--r--server/lib/schedulers/remove-old-history-scheduler.ts32
2 files changed, 34 insertions, 1 deletions
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 @@
1import { logger } from '../../helpers/logger' 1import { logger } from '../../helpers/logger'
2import * as Bluebird from 'bluebird'
2 3
3export abstract class AbstractScheduler { 4export abstract class AbstractScheduler {
4 5
@@ -30,5 +31,5 @@ export abstract class AbstractScheduler {
30 } 31 }
31 } 32 }
32 33
33 protected abstract internalExecute (): Promise<any> 34 protected abstract internalExecute (): Promise<any> | Bluebird<any>
34} 35}
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 @@
1import { logger } from '../../helpers/logger'
2import { AbstractScheduler } from './abstract-scheduler'
3import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants'
4import { UserVideoHistoryModel } from '../../models/account/user-video-history'
5import { CONFIG } from '../../initializers/config'
6import { isTestInstance } from '../../helpers/core-utils'
7
8export 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}