From 91c72729d893d89522da0d273fbb4c0bceaf79c3 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 31 Oct 2022 08:57:52 +0100 Subject: Prevent error in redundancy scheduler --- .../lib/schedulers/videos-redundancy-scheduler.ts | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'server/lib/schedulers/videos-redundancy-scheduler.ts') diff --git a/server/lib/schedulers/videos-redundancy-scheduler.ts b/server/lib/schedulers/videos-redundancy-scheduler.ts index 78245fa6a..dc450c338 100644 --- a/server/lib/schedulers/videos-redundancy-scheduler.ts +++ b/server/lib/schedulers/videos-redundancy-scheduler.ts @@ -115,16 +115,29 @@ export class VideosRedundancyScheduler extends AbstractScheduler { for (const redundancyModel of expired) { try { const redundancyConfig = CONFIG.REDUNDANCY.VIDEOS.STRATEGIES.find(s => s.strategy === redundancyModel.strategy) + + // If the admin disabled the redundancy, remove this redundancy instead of extending it + if (!redundancyConfig) { + logger.info( + 'Destroying redundancy %s because the redundancy %s does not exist anymore.', + redundancyModel.url, redundancyModel.strategy + ) + + await removeVideoRedundancy(redundancyModel) + continue + } + const { totalUsed } = await VideoRedundancyModel.getStats(redundancyConfig.strategy) - // If the administrator disabled the redundancy or decreased the cache size, remove this redundancy instead of extending it - if (!redundancyConfig || totalUsed > redundancyConfig.size) { + // If the admin decreased the cache size, remove this redundancy instead of extending it + if (totalUsed > redundancyConfig.size) { logger.info('Destroying redundancy %s because the cache size %s is too heavy.', redundancyModel.url, redundancyModel.strategy) await removeVideoRedundancy(redundancyModel) - } else { - await this.extendsRedundancy(redundancyModel) + continue } + + await this.extendsRedundancy(redundancyModel) } catch (err) { logger.error( 'Cannot extend or remove expiration of %s video from our redundancy system.', -- cgit v1.2.3