1
0
Fork 0

Add redundancy check interval in config

This commit is contained in:
Chocobozzz 2018-09-19 16:21:09 +02:00
parent d9bdd007d7
commit f9f899b9f8
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
6 changed files with 18 additions and 12 deletions

View File

@ -71,6 +71,7 @@ trending:
# Once you have defined your strategies, choose which instances you want to cache in admin -> manage follows -> following # Once you have defined your strategies, choose which instances you want to cache in admin -> manage follows -> following
redundancy: redundancy:
videos: videos:
check_interval: '1 hour' # How often you want to check new videos to cache
strategies: strategies:
# - # -
# size: '10GB' # size: '10GB'

View File

@ -72,6 +72,7 @@ trending:
# Once you have defined your strategies, choose which instances you want to cache in admin -> manage follows -> following # Once you have defined your strategies, choose which instances you want to cache in admin -> manage follows -> following
redundancy: redundancy:
videos: videos:
check_interval: '1 hour' # How often you want to check new videos to cache
strategies: strategies:
# - # -
# size: '10GB' # size: '10GB'

View File

@ -23,6 +23,7 @@ log:
redundancy: redundancy:
videos: videos:
check_interval: '5 seconds'
strategies: strategies:
- -
size: '10MB' size: '10MB'

View File

@ -75,7 +75,7 @@ function checkMissedConfig () {
'cache.previews.size', 'admin.email', 'cache.previews.size', 'admin.email',
'signup.enabled', 'signup.limit', 'signup.requires_email_verification', 'signup.enabled', 'signup.limit', 'signup.requires_email_verification',
'signup.filters.cidr.whitelist', 'signup.filters.cidr.blacklist', 'signup.filters.cidr.whitelist', 'signup.filters.cidr.blacklist',
'redundancy.videos.strategies', 'redundancy.videos.strategies', 'redundancy.videos.check_interval',
'transcoding.enabled', 'transcoding.threads', 'transcoding.enabled', 'transcoding.threads',
'import.videos.http.enabled', 'import.videos.torrent.enabled', 'import.videos.http.enabled', 'import.videos.torrent.enabled',
'trending.videos.interval_days', 'trending.videos.interval_days',

View File

@ -5,7 +5,7 @@ import { ActivityPubActorType } from '../../shared/models/activitypub'
import { FollowState } from '../../shared/models/actors' import { FollowState } from '../../shared/models/actors'
import { VideoAbuseState, VideoImportState, VideoPrivacy } from '../../shared/models/videos' import { VideoAbuseState, VideoImportState, VideoPrivacy } from '../../shared/models/videos'
// Do not use barrels, remain constants as independent as possible // Do not use barrels, remain constants as independent as possible
import { buildPath, isTestInstance, root, sanitizeHost, sanitizeUrl } from '../helpers/core-utils' import { buildPath, isTestInstance, parseDuration, root, sanitizeHost, sanitizeUrl } from '../helpers/core-utils'
import { NSFWPolicyType } from '../../shared/models/videos/nsfw-policy.type' import { NSFWPolicyType } from '../../shared/models/videos/nsfw-policy.type'
import { invert } from 'lodash' import { invert } from 'lodash'
import { CronRepeatOptions, EveryRepeatOptions } from 'bull' import { CronRepeatOptions, EveryRepeatOptions } from 'bull'
@ -139,8 +139,7 @@ let SCHEDULER_INTERVALS_MS = {
badActorFollow: 60000 * 60, // 1 hour badActorFollow: 60000 * 60, // 1 hour
removeOldJobs: 60000 * 60, // 1 hour removeOldJobs: 60000 * 60, // 1 hour
updateVideos: 60000, // 1 minute updateVideos: 60000, // 1 minute
youtubeDLUpdate: 60000 * 60 * 24, // 1 day youtubeDLUpdate: 60000 * 60 * 24 // 1 day
videosRedundancy: 60000 * 2 // 2 hours
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
@ -213,6 +212,7 @@ const CONFIG = {
}, },
REDUNDANCY: { REDUNDANCY: {
VIDEOS: { VIDEOS: {
CHECK_INTERVAL: parseDuration(config.get<string>('redundancy.videos.check_interval')),
STRATEGIES: buildVideosRedundancy(config.get<any[]>('redundancy.videos.strategies')) STRATEGIES: buildVideosRedundancy(config.get<any[]>('redundancy.videos.strategies'))
} }
}, },
@ -651,7 +651,6 @@ if (isTestInstance() === true) {
SCHEDULER_INTERVALS_MS.badActorFollow = 10000 SCHEDULER_INTERVALS_MS.badActorFollow = 10000
SCHEDULER_INTERVALS_MS.removeOldJobs = 10000 SCHEDULER_INTERVALS_MS.removeOldJobs = 10000
SCHEDULER_INTERVALS_MS.updateVideos = 5000 SCHEDULER_INTERVALS_MS.updateVideos = 5000
SCHEDULER_INTERVALS_MS.videosRedundancy = 5000
REPEAT_JOBS['videos-views'] = { every: 5000 } REPEAT_JOBS['videos-views'] = { every: 5000 }
REDUNDANCY.VIDEOS.RANDOMIZED_FACTOR = 1 REDUNDANCY.VIDEOS.RANDOMIZED_FACTOR = 1

View File

@ -18,7 +18,7 @@ export class VideosRedundancyScheduler extends AbstractScheduler {
private static instance: AbstractScheduler private static instance: AbstractScheduler
private executing = false private executing = false
protected schedulerIntervalMs = SCHEDULER_INTERVALS_MS.videosRedundancy protected schedulerIntervalMs = CONFIG.REDUNDANCY.VIDEOS.CHECK_INTERVAL
private constructor () { private constructor () {
super() super()
@ -50,6 +50,16 @@ export class VideosRedundancyScheduler extends AbstractScheduler {
} }
} }
await this.removeExpired()
this.executing = false
}
static get Instance () {
return this.instance || (this.instance = new this())
}
private async removeExpired () {
const expired = await VideoRedundancyModel.listAllExpired() const expired = await VideoRedundancyModel.listAllExpired()
for (const m of expired) { for (const m of expired) {
@ -61,12 +71,6 @@ export class VideosRedundancyScheduler extends AbstractScheduler {
logger.error('Cannot remove %s video from our redundancy system.', this.buildEntryLogId(m)) logger.error('Cannot remove %s video from our redundancy system.', this.buildEntryLogId(m))
} }
} }
this.executing = false
}
static get Instance () {
return this.instance || (this.instance = new this())
} }
private findVideoToDuplicate (cache: VideosRedundancy) { private findVideoToDuplicate (cache: VideosRedundancy) {