diff options
| author | JP Dillingham <jp@dillingham.me> | 2023-09-18 08:46:09 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-09-18 08:46:09 -0500 |
| commit | 77ec3da43c11449d2d4ae64c1413505f7a7741a2 (patch) | |
| tree | 3eb7d438339be0b7e7b8ef2ded969231422d26fa /src/slskd/Core | |
| parent | a505a5ee4072d0f50e747e05e1f4b1de86f4c396 (diff) | |
| parent | 4cdefceae542f59de2d55ffcafc03f2af5edfcc9 (diff) | |
| download | slskd-77ec3da43c11449d2d4ae64c1413505f7a7741a2.tar.gz | |
Merge pull request #972 from slskd/scheduler
Add retention settings for transfers, check for 'expired' transfers on a 5 minute interval and remove (soft delete) them
Diffstat (limited to 'src/slskd/Core')
| -rw-r--r-- | src/slskd/Core/Clock.cs | 27 | ||||
| -rw-r--r-- | src/slskd/Core/Options.cs | 48 |
2 files changed, 73 insertions, 2 deletions
diff --git a/src/slskd/Core/Clock.cs b/src/slskd/Core/Clock.cs index 4d2e6c10..332308d7 100644 --- a/src/slskd/Core/Clock.cs +++ b/src/slskd/Core/Clock.cs @@ -28,13 +28,36 @@ namespace slskd static Clock() { 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); } /// <summary> - /// Fires every 60 seconds. + /// Fires every minute. /// </summary> public static event EventHandler EveryMinute; - private static Timer EveryMinuteTimer { get; } = new Timer() { AutoReset = true, Interval = 60000, Enabled = true }; + /// <summary> + /// Fires every 5 minutes. + /// </summary> + public static event EventHandler EveryFiveMinutes; + + /// <summary> + /// Fires every 30 minutes. + /// </summary> + public static event EventHandler EveryThirtyMinutes; + + /// <summary> + /// Fires every hour. + /// </summary> + 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 }; } }
\ No newline at end of file diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs index 2ee21733..30297cac 100644 --- a/src/slskd/Core/Options.cs +++ b/src/slskd/Core/Options.cs @@ -254,6 +254,12 @@ namespace slskd public WebOptions Web { get; init; } = new WebOptions(); /// <summary> + /// Gets retention options. + /// </summary> + [Validate] + public RetentionOptions Retention { get; init; } = new RetentionOptions(); + + /// <summary> /// Gets logger options. /// </summary> [Validate] @@ -1049,6 +1055,48 @@ namespace slskd } /// <summary> + /// Retention options. + /// </summary> + public class RetentionOptions + { + /// <summary> + /// Gets upload retention options. + /// </summary> + [Validate] + public TransferRetentionOptions Upload { get; init; } = new TransferRetentionOptions(); + + /// <summary> + /// Gets download retention options. + /// </summary> + [Validate] + public TransferRetentionOptions Download { get; init; } = new TransferRetentionOptions(); + + /// <summary> + /// Transfer retention options. + /// </summary> + public class TransferRetentionOptions + { + /// <summary> + /// Gets the time to retain successful transfers, in minutes. + /// </summary> + [Range(5, maximum: int.MaxValue)] + public int? Succeeded { get; init; } = null; + + /// <summary> + /// Gets the time to retain errored transfers, in minutes. + /// </summary> + [Range(5, maximum: int.MaxValue)] + public int? Errored { get; init; } = null; + + /// <summary> + /// Gets the time to retain cancelled transfers, in minutes. + /// </summary> + [Range(5, maximum: int.MaxValue)] + public int? Cancelled { get; init; } = null; + } + } + + /// <summary> /// Metrics options. /// </summary> public class MetricsOptions |
