From cf5a29422198e4defc3820edf8b160f9bcd00857 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 16 Sep 2023 22:54:16 -0500 Subject: add retention options --- src/slskd/Core/Options.cs | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'src/slskd/Core') diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs index 2ee21733..b2c85146 100644 --- a/src/slskd/Core/Options.cs +++ b/src/slskd/Core/Options.cs @@ -253,6 +253,12 @@ namespace slskd [Validate] public WebOptions Web { get; init; } = new WebOptions(); + /// + /// Gets retention options. + /// + [Validate] + public RetentionOptions Retention { get; init; } = new RetentionOptions(); + /// /// Gets logger options. /// @@ -1048,6 +1054,48 @@ namespace slskd public string Loki { get; init; } = null; } + /// + /// Retention options. + /// + public class RetentionOptions + { + /// + /// Gets upload retention options. + /// + [Validate] + public TransferRetentionOptions Upload { get; init; } = new TransferRetentionOptions(); + + /// + /// Gets download retention options. + /// + [Validate] + public TransferRetentionOptions Download { get; init; } = new TransferRetentionOptions(); + + /// + /// Transfer retention options. + /// + public class TransferRetentionOptions + { + /// + /// Gets the time to retain successful transfers, in minutes. + /// + [Range(60, maximum: int.MaxValue)] + public int Succeeded { get; init; } = int.MaxValue; + + /// + /// Gets the time to retain errored transfers, in minutes. + /// + [Range(60, maximum: int.MaxValue)] + public int Errored { get; init; } = int.MaxValue; + + /// + /// Gets the time to retain cancelled transfers, in minutes. + /// + [Range(60, maximum: int.MaxValue)] + public int Cancelled { get; init; } = int.MaxValue; + } + } + /// /// Metrics options. /// -- cgit v1.2.3 From 5966f7fe0245110591cbf5634efcb301712763a8 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 16 Sep 2023 22:56:48 -0500 Subject: specify retention in hours --- src/slskd/Core/Options.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/slskd/Core') diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs index b2c85146..7e21865f 100644 --- a/src/slskd/Core/Options.cs +++ b/src/slskd/Core/Options.cs @@ -1077,21 +1077,21 @@ namespace slskd public class TransferRetentionOptions { /// - /// Gets the time to retain successful transfers, in minutes. + /// Gets the time to retain successful transfers, in hours. /// - [Range(60, maximum: int.MaxValue)] + [Range(1, maximum: int.MaxValue)] public int Succeeded { get; init; } = int.MaxValue; /// - /// Gets the time to retain errored transfers, in minutes. + /// Gets the time to retain errored transfers, in hours. /// - [Range(60, maximum: int.MaxValue)] + [Range(1, maximum: int.MaxValue)] public int Errored { get; init; } = int.MaxValue; /// - /// Gets the time to retain cancelled transfers, in minutes. + /// Gets the time to retain cancelled transfers, in hours. /// - [Range(60, maximum: int.MaxValue)] + [Range(1, maximum: int.MaxValue)] public int Cancelled { get; init; } = int.MaxValue; } } -- cgit v1.2.3 From 4e963e5aa70259f31d20b270e94d7bb6f897cc12 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 16 Sep 2023 22:59:15 -0500 Subject: add EveryFiveMinutes and EveryHour clock events --- src/slskd/Core/Clock.cs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/slskd/Core') diff --git a/src/slskd/Core/Clock.cs b/src/slskd/Core/Clock.cs index 4d2e6c10..4e7b3866 100644 --- a/src/slskd/Core/Clock.cs +++ b/src/slskd/Core/Clock.cs @@ -28,6 +28,8 @@ namespace slskd static Clock() { EveryMinuteTimer.Elapsed += (_, _) => EveryMinute?.Invoke(null, EventArgs.Empty); + EveryFiveMinutesTimer.Elapsed += (_, _) => EveryFiveMinutes?.Invoke(null, EventArgs.Empty); + EveryHourTimer.Elapsed += (_, _) => EveryHour?.Invoke(null, EventArgs.Empty); } /// @@ -35,6 +37,20 @@ namespace slskd /// public static event EventHandler EveryMinute; - private static Timer EveryMinuteTimer { get; } = new Timer() { AutoReset = true, Interval = 60000, Enabled = true }; + /// + /// Fires every 5 minutes. + /// + public static event EventHandler EveryFiveMinutes; + + /// + /// Fires every 60 minutes. + /// + public static event EventHandler EveryHour; + + private static Timer EveryMinuteTimer { get; } = CreateTimer(interval: 1000 * 60); + private static Timer EveryFiveMinutesTimer { get; } = CreateTimer(interval: 1000 * 60 * 5); + private static Timer EveryHourTimer { get; } = CreateTimer(interval: 1000 * 60 * 60); + + private static Timer CreateTimer(double interval) => new() { AutoReset = true, Interval = interval, Enabled = true }; } } \ No newline at end of file -- cgit v1.2.3 From 5e79b99824ef85832ee9399b149c46c3b35d8411 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 17 Sep 2023 16:31:20 -0500 Subject: add another clock event --- src/slskd/Core/Clock.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/slskd/Core') diff --git a/src/slskd/Core/Clock.cs b/src/slskd/Core/Clock.cs index 4e7b3866..332308d7 100644 --- a/src/slskd/Core/Clock.cs +++ b/src/slskd/Core/Clock.cs @@ -29,11 +29,12 @@ namespace slskd { EveryMinuteTimer.Elapsed += (_, _) => EveryMinute?.Invoke(null, EventArgs.Empty); EveryFiveMinutesTimer.Elapsed += (_, _) => EveryFiveMinutes?.Invoke(null, EventArgs.Empty); + EveryThirtyMinutesTimer.Elapsed += (_, _) => EveryThirtyMinutes?.Invoke(null, EventArgs.Empty); EveryHourTimer.Elapsed += (_, _) => EveryHour?.Invoke(null, EventArgs.Empty); } /// - /// Fires every 60 seconds. + /// Fires every minute. /// public static event EventHandler EveryMinute; @@ -43,12 +44,18 @@ namespace slskd public static event EventHandler EveryFiveMinutes; /// - /// Fires every 60 minutes. + /// Fires every 30 minutes. + /// + public static event EventHandler EveryThirtyMinutes; + + /// + /// Fires every hour. /// public static event EventHandler EveryHour; private static Timer EveryMinuteTimer { get; } = CreateTimer(interval: 1000 * 60); private static Timer EveryFiveMinutesTimer { get; } = CreateTimer(interval: 1000 * 60 * 5); + private static Timer EveryThirtyMinutesTimer { get; } = CreateTimer(interval: 1000 * 60 * 30); private static Timer EveryHourTimer { get; } = CreateTimer(interval: 1000 * 60 * 60); private static Timer CreateTimer(double interval) => new() { AutoReset = true, Interval = interval, Enabled = true }; -- cgit v1.2.3 From 98536d94108044b709658895782ba25d5693825b Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 17 Sep 2023 16:40:58 -0500 Subject: make retention options nullable, and in minutes --- config/slskd.example.yml | 12 ++++++------ src/slskd/Core/Options.cs | 18 +++++++++--------- 2 files changed, 15 insertions(+), 15 deletions(-) (limited to 'src/slskd/Core') diff --git a/config/slskd.example.yml b/config/slskd.example.yml index 5b7ea7ae..2c22d020 100644 --- a/config/slskd.example.yml +++ b/config/slskd.example.yml @@ -109,13 +109,13 @@ # cidr: 0.0.0.0/0,::/0 # retention: # upload: -# succeeded: 2147483647 -# errored: 2147483647 -# cancelled: 2147483647 +# succeeded: 1440 # 1 day +# errored: 30 +# cancelled: 5 # download: -# succeeded: 2147483647 -# errored: 2147483647 -# cancelled: 2147483647 +# succeeded: 1440 # 1 day +# errored: 20160 # 2 weeks +# cancelled: 5 # logger: # loki: ~ # metrics: diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs index 7e21865f..30297cac 100644 --- a/src/slskd/Core/Options.cs +++ b/src/slskd/Core/Options.cs @@ -1077,22 +1077,22 @@ namespace slskd public class TransferRetentionOptions { /// - /// Gets the time to retain successful transfers, in hours. + /// Gets the time to retain successful transfers, in minutes. /// - [Range(1, maximum: int.MaxValue)] - public int Succeeded { get; init; } = int.MaxValue; + [Range(5, maximum: int.MaxValue)] + public int? Succeeded { get; init; } = null; /// - /// Gets the time to retain errored transfers, in hours. + /// Gets the time to retain errored transfers, in minutes. /// - [Range(1, maximum: int.MaxValue)] - public int Errored { get; init; } = int.MaxValue; + [Range(5, maximum: int.MaxValue)] + public int? Errored { get; init; } = null; /// - /// Gets the time to retain cancelled transfers, in hours. + /// Gets the time to retain cancelled transfers, in minutes. /// - [Range(1, maximum: int.MaxValue)] - public int Cancelled { get; init; } = int.MaxValue; + [Range(5, maximum: int.MaxValue)] + public int? Cancelled { get; init; } = null; } } -- cgit v1.2.3