Add hour intervals for Seeker (#578)

This commit is contained in:
Flaminel
2026-04-21 16:56:58 +03:00
committed by GitHub
parent 24ecd88cd0
commit 8770a8b18e
4 changed files with 32 additions and 4 deletions

View File

@@ -28,6 +28,11 @@ public sealed class SeekerConfigTests
[InlineData((ushort)15)]
[InlineData((ushort)20)]
[InlineData((ushort)30)]
[InlineData((ushort)60)]
[InlineData((ushort)120)]
[InlineData((ushort)180)]
[InlineData((ushort)240)]
[InlineData((ushort)360)]
public void Validate_WithValidIntervals_DoesNotThrow(ushort interval)
{
var config = new SeekerConfig { SearchInterval = interval };
@@ -51,7 +56,7 @@ public sealed class SeekerConfigTests
[Fact]
public void Validate_WithIntervalAboveMaximum_ThrowsValidationException()
{
var config = new SeekerConfig { SearchInterval = 31 };
var config = new SeekerConfig { SearchInterval = 361 };
var exception = Should.Throw<ValidationException>(() => config.Validate());
exception.Message.ShouldContain("at most");
@@ -81,6 +86,11 @@ public sealed class SeekerConfigTests
[InlineData((ushort)5, "0 */5 * * * ?")]
[InlineData((ushort)10, "0 */10 * * * ?")]
[InlineData((ushort)30, "0 */30 * * * ?")]
[InlineData((ushort)60, "0 0 * * * ?")]
[InlineData((ushort)120, "0 0 */2 * * ?")]
[InlineData((ushort)180, "0 0 */3 * * ?")]
[InlineData((ushort)240, "0 0 */4 * * ?")]
[InlineData((ushort)360, "0 0 */6 * * ?")]
public void ToCronExpression_ReturnsCorrectCron(ushort interval, string expectedCron)
{
var config = new SeekerConfig { SearchInterval = interval };

View File

@@ -63,7 +63,7 @@ public sealed record SeekerConfig : IConfig
$"{nameof(SearchInterval)} must be at most {Constants.MaxSearchIntervalMinutes} minutes");
}
if (!new List<int> { 2, 3, 4, 5, 6, 10, 12, 15, 20, 30 }.Contains(SearchInterval))
if (!new List<int> { 2, 3, 4, 5, 6, 10, 12, 15, 20, 30, 60, 120, 180, 240, 360 }.Contains(SearchInterval))
{
throw new ValidationException($"Invalid search interval {SearchInterval}");
}
@@ -77,5 +77,18 @@ public sealed record SeekerConfig : IConfig
/// <summary>
/// Generates the internal cron expression from the SearchInterval.
/// </summary>
public string ToCronExpression() => $"0 */{SearchInterval} * * * ?";
public string ToCronExpression()
{
if (SearchInterval < 60)
{
return $"0 */{SearchInterval} * * * ?";
}
if (SearchInterval == 60)
{
return "0 0 * * * ?";
}
return $"0 0 */{SearchInterval / 60} * * ?";
}
}

View File

@@ -17,7 +17,7 @@ public static class Constants
public const ushort DefaultSearchIntervalMinutes = 3;
public const ushort MinSearchIntervalMinutes = 2;
public const ushort MaxSearchIntervalMinutes = 30;
public const ushort MaxSearchIntervalMinutes = 360;
public const string LogoUrl = "https://cdn.jsdelivr.net/gh/Cleanuparr/Cleanuparr@main/Logo/48.png";

View File

@@ -27,6 +27,11 @@ const INTERVAL_OPTIONS: SelectOption[] = [
{ label: '15 minutes', value: 15 },
{ label: '20 minutes', value: 20 },
{ label: '30 minutes', value: 30 },
{ label: '1 hour', value: 60 },
{ label: '2 hours', value: 120 },
{ label: '3 hours', value: 180 },
{ label: '4 hours', value: 240 },
{ label: '6 hours', value: 360 },
];
const STRATEGY_OPTIONS: SelectOption[] = [