fix: try to fix database connections not being closed sometimes

This commit is contained in:
sam 2025-02-11 15:28:12 +01:00
parent 1a63540f89
commit db3e6fa7b0
Signed by: sam
GPG key ID: 5F3C3C1B3166639D
2 changed files with 21 additions and 8 deletions

View file

@ -25,7 +25,8 @@ public class TimeoutService(
_logger.Information("Populating timeout service with existing database timeouts");
await using var scope = serviceProvider.CreateAsyncScope();
var timeoutRepository = scope.ServiceProvider.GetRequiredService<TimeoutRepository>();
await using var timeoutRepository =
scope.ServiceProvider.GetRequiredService<TimeoutRepository>();
var timeouts = await timeoutRepository.GetAllAsync();
foreach (var timeout in timeouts)
@ -53,8 +54,10 @@ public class TimeoutService(
_logger.Information("Sending timeout log for {TimeoutId}", timeoutId);
await using var scope = serviceProvider.CreateAsyncScope();
var guildRepository = scope.ServiceProvider.GetRequiredService<GuildRepository>();
var timeoutRepository = scope.ServiceProvider.GetRequiredService<TimeoutRepository>();
await using var guildRepository =
scope.ServiceProvider.GetRequiredService<GuildRepository>();
await using var timeoutRepository =
scope.ServiceProvider.GetRequiredService<TimeoutRepository>();
var timeout = await timeoutRepository.RemoveAsync(timeoutId);
if (timeout == null)