Foxnouns.NET/Foxnouns.Backend/Services/PeriodicTasksService.cs
sam 903be2709c
feat(backend): initial data export support
obviously it's missing things that haven't been added yet
2024-12-02 18:06:19 +01:00

26 lines
960 B
C#

namespace Foxnouns.Backend.Services;
public class PeriodicTasksService(ILogger logger, IServiceProvider services) : BackgroundService
{
private readonly ILogger _logger = logger.ForContext<PeriodicTasksService>();
protected override async Task ExecuteAsync(CancellationToken ct)
{
using var timer = new PeriodicTimer(TimeSpan.FromMinutes(1));
while (await timer.WaitForNextTickAsync(ct))
await RunPeriodicTasksAsync(ct);
}
private async Task RunPeriodicTasksAsync(CancellationToken ct)
{
_logger.Debug("Running periodic tasks");
await using var scope = services.CreateAsyncScope();
var keyCacheService = scope.ServiceProvider.GetRequiredService<KeyCacheService>();
var dataCleanupService = scope.ServiceProvider.GetRequiredService<DataCleanupService>();
await keyCacheService.DeleteExpiredKeysAsync(ct);
await dataCleanupService.InvokeAsync(ct);
}
}