From e6d3929fc91e7e3da4e1db3b6c6882244cc8e2aa Mon Sep 17 00:00:00 2001 From: Flaminel Date: Tue, 11 Mar 2025 23:35:07 +0200 Subject: [PATCH] Restrict max strikes to a minimum value (#87) --- .../Configuration/QueueCleaner/QueueCleanerConfig.cs | 12 +++++++++++- .../Verticals/QueueCleaner/QueueCleaner.cs | 1 + variables.md | 4 ++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/code/Common/Configuration/QueueCleaner/QueueCleanerConfig.cs b/code/Common/Configuration/QueueCleaner/QueueCleanerConfig.cs index f0d7049..9006253 100644 --- a/code/Common/Configuration/QueueCleaner/QueueCleanerConfig.cs +++ b/code/Common/Configuration/QueueCleaner/QueueCleanerConfig.cs @@ -1,4 +1,5 @@ -using Microsoft.Extensions.Configuration; +using Common.Exceptions; +using Microsoft.Extensions.Configuration; namespace Common.Configuration.QueueCleaner; @@ -39,5 +40,14 @@ public sealed record QueueCleanerConfig : IJobConfig, IIgnoredDownloadsConfig public void Validate() { + if (ImportFailedMaxStrikes is > 0 and < 3) + { + throw new ValidationException("the minimum value for IMPORT_FAILED_MAX_STRIKES must be 3"); + } + + if (StalledMaxStrikes is > 0 and < 3) + { + throw new ValidationException("the minimum value for STALLED_MAX_STRIKES must be 3"); + } } } \ No newline at end of file diff --git a/code/Infrastructure/Verticals/QueueCleaner/QueueCleaner.cs b/code/Infrastructure/Verticals/QueueCleaner/QueueCleaner.cs index e422a5c..bc7df16 100644 --- a/code/Infrastructure/Verticals/QueueCleaner/QueueCleaner.cs +++ b/code/Infrastructure/Verticals/QueueCleaner/QueueCleaner.cs @@ -45,6 +45,7 @@ public sealed class QueueCleaner : GenericHandler ) { _config = config.Value; + _config.Validate(); _ignoredDownloadsProvider = ignoredDownloadsProvider; } diff --git a/variables.md b/variables.md index dbc0aaf..905aee1 100644 --- a/variables.md +++ b/variables.md @@ -114,7 +114,7 @@ - Set to `0` to never remove failed imports. - A strike is given when an item is stalled, stuck in metadata downloading, or failed to be imported. - Type: Integer -- Possible values: `0` or greater +- Possible values: `0` or a number greater than `2`. - Default: `0` - Required: No. @@ -153,7 +153,7 @@ QUEUECLEANER__IMPORT_FAILED_IGNORE_PATTERNS__1: "manual import required" - Set to `0` to never remove stalled downloads. - A strike is given when download speed is 0. - Type: Integer -- Possible values: `0` or greater +- Possible values: `0` or a number greater than `2`. - Default: `0` - Required: No.