aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Core
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2023-10-15 14:27:13 -0500
committerGitHub <noreply@github.com>2023-10-15 14:27:13 -0500
commit5986bcadc179e3e9a34152687b80210dcc65e366 (patch)
tree69c89224d513f513793ac415664b4b584c383a82 /src/slskd/Core
parent12e89983470a55e03f30f35002135b921183c72b (diff)
parent4670f2a708b48d3bb73021a3954b8ca76bf56aa5 (diff)
downloadslskd-5986bcadc179e3e9a34152687b80210dcc65e366.tar.gz
Merge pull request #978 from slskd/file-retention
Add automated removal of downloaded and incomplete files, and application logs
Diffstat (limited to 'src/slskd/Core')
-rw-r--r--src/slskd/Core/Clock.cs41
-rw-r--r--src/slskd/Core/Options.cs30
2 files changed, 66 insertions, 5 deletions
diff --git a/src/slskd/Core/Clock.cs b/src/slskd/Core/Clock.cs
index 332308d7..31519fc8 100644
--- a/src/slskd/Core/Clock.cs
+++ b/src/slskd/Core/Clock.cs
@@ -18,6 +18,7 @@
namespace slskd
{
using System;
+ using System.Threading.Tasks;
using System.Timers;
/// <summary>
@@ -27,10 +28,10 @@ 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);
+ EveryMinuteTimer.Elapsed += (_, _) => Fire(EveryMinute);
+ EveryFiveMinutesTimer.Elapsed += (_, _) => Fire(EveryFiveMinutes);
+ EveryThirtyMinutesTimer.Elapsed += (_, _) => Fire(EveryThirtyMinutes);
+ EveryHourTimer.Elapsed += (_, _) => Fire(EveryHour);
}
/// <summary>
@@ -53,11 +54,41 @@ namespace slskd
/// </summary>
public static event EventHandler EveryHour;
+ /// <summary>
+ /// Starts the clock.
+ /// </summary>
+ /// <returns>A Task that completes when all startup events have finished processing.</returns>
+ public static Task StartAsync()
+ {
+ EveryMinuteTimer.Enabled = true;
+ EveryFiveMinutesTimer.Enabled = true;
+ EveryThirtyMinutesTimer.Enabled = true;
+ EveryHourTimer.Enabled = true;
+
+ return Task.WhenAll(
+ Task.Run(() => Fire(EveryMinute)),
+ Task.Run(() => Fire(EveryFiveMinutes)),
+ Task.Run(() => Fire(EveryThirtyMinutes)),
+ Task.Run(() => Fire(EveryHour)));
+ }
+
+ /// <summary>
+ /// Stops the clock.
+ /// </summary>
+ public static void Stop()
+ {
+ EveryMinuteTimer.Stop();
+ EveryFiveMinutesTimer.Stop();
+ EveryThirtyMinutesTimer.Stop();
+ EveryHourTimer.Stop();
+ }
+
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 };
+ private static Timer CreateTimer(double interval) => new() { AutoReset = true, Interval = interval, Enabled = false };
+ private static void Fire(EventHandler e) => e?.Invoke(null, EventArgs.Empty);
}
} \ No newline at end of file
diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs
index 30297cac..9d92bb95 100644
--- a/src/slskd/Core/Options.cs
+++ b/src/slskd/Core/Options.cs
@@ -1060,6 +1060,12 @@ namespace slskd
public class RetentionOptions
{
/// <summary>
+ /// Gets file retention options.
+ /// </summary>
+ [Validate]
+ public FileRetentionOptions Files { get; init; } = new FileRetentionOptions();
+
+ /// <summary>
/// Gets upload retention options.
/// </summary>
[Validate]
@@ -1072,6 +1078,30 @@ namespace slskd
public TransferRetentionOptions Download { get; init; } = new TransferRetentionOptions();
/// <summary>
+ /// Gets the time to retain logs, in days.
+ /// </summary>
+ [Range(1, maximum: int.MaxValue)]
+ public int Logs { get; init; } = 180;
+
+ /// <summary>
+ /// File retention options.
+ /// </summary>
+ public class FileRetentionOptions
+ {
+ /// <summary>
+ /// Gets the time to retain completed files, in minutes.
+ /// </summary>
+ [Range(30, maximum: int.MaxValue)]
+ public int? Complete { get; init; } = null;
+
+ /// <summary>
+ /// Gets the time to retain incomplete files, in minutes.
+ /// </summary>
+ [Range(30, maximum: int.MaxValue)]
+ public int? Incomplete { get; init; } = null;
+ }
+
+ /// <summary>
/// Transfer retention options.
/// </summary>
public class TransferRetentionOptions