Add data management, randomized HTML drip and public README

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
TomandClaude Opus 5.5 committed 2026-11-14 16:08:45 +01:00
1 parent 3671019e60
commit f5d8ca7484
46 files changed
+1601 -172

No files matched your search

@@ -0,0 +1,62 @@
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
namespace Flypaper.Storage.Maintenance;
internal sealed partial class RetentionCleanup(
TrapDataMaintenance maintenance,
IOptionsMonitor<RetentionOptions> options,
TimeProvider timeProvider,
ILogger<RetentionCleanup> logger) : BackgroundService
{
private const int VacuumThreshold = 5_000;
private static readonly TimeSpan Interval = TimeSpan.FromDays(1);
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
while (true)
{
try
{
await CleanupAsync(stoppingToken);
}
catch (Exception ex) when (ex is not OperationCanceledException)
{
LogCleanupFailed(ex);
}
await Task.Delay(Interval, timeProvider, stoppingToken);
}
}
internal async Task<int> CleanupAsync(CancellationToken ct)
{
var days = options.CurrentValue.Days;
if (days <= 0)
{
return 0;
}
var cutoff = timeProvider.GetUtcNow().UtcDateTime.AddDays(-days);
var deleted = await maintenance.DeleteOlderThanAsync(cutoff, ct);
if (deleted == 0)
{
return 0;
}
LogDeleted(deleted, days);
if (deleted >= VacuumThreshold)
{
await maintenance.VacuumAsync(ct);
}
return deleted;
}
[LoggerMessage(Level = LogLevel.Information, Message = "Deleted {Count} trap events older than {Days} days")]
private partial void LogDeleted(int count, int days);
[LoggerMessage(Level = LogLevel.Warning, Message = "Retention cleanup failed")]
private partial void LogCleanupFailed(Exception exception);
}