feat: clear timeouts that never get logged

This commit is contained in:
sam 2024-11-13 15:14:22 +01:00
parent 0564206bf7
commit 254a50da4d
Signed by: sam
GPG key ID: 5F3C3C1B3166639D
2 changed files with 18 additions and 3 deletions

View file

@ -35,16 +35,23 @@ public class BackgroundTasksService(ILogger logger, IServiceProvider services) :
await using var scope = services.CreateAsyncScope();
await using var messageRepository =
scope.ServiceProvider.GetRequiredService<MessageRepository>();
await using var timeoutRepository =
scope.ServiceProvider.GetRequiredService<TimeoutRepository>();
var (msgCount, ignoredCount) = await messageRepository.DeleteExpiredMessagesAsync();
if (msgCount != 0 || ignoredCount != 0)
{
_logger.Information(
"Deleted {Count} messages and {IgnoredCount} ignored message IDs older than {MaxDays} days old",
msgCount,
ignoredCount,
MessageRepository.MaxMessageAgeDays
);
}
var timeoutCount = await timeoutRepository.RemoveExpiredTimeoutsAsync();
if (timeoutCount != 0)
_logger.Information(
"Deleted {Count} expired timeouts that were never logged",
timeoutCount
);
}
}