refactor: replace periodic tasks loop with background service

This commit is contained in:
sam 2024-09-04 01:46:39 +02:00
parent 54ec469cd9
commit fb324e7576
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
4 changed files with 67 additions and 57 deletions

View file

@ -37,9 +37,9 @@ public class KeyCacheService(DatabaseContext db, IClock clock, ILogger logger)
return value.Value;
}
public async Task DeleteExpiredKeysAsync()
public async Task DeleteExpiredKeysAsync(CancellationToken ct)
{
var count = await db.TemporaryKeys.Where(k => k.Expires < clock.GetCurrentInstant()).ExecuteDeleteAsync();
var count = await db.TemporaryKeys.Where(k => k.Expires < clock.GetCurrentInstant()).ExecuteDeleteAsync(ct);
if (count != 0) logger.Information("Removed {Count} expired keys from the database", count);
}