Refactor StartMaintenance method to return void and simplify maintenance loop

This commit is contained in:
Thorsten Sommer 2025-10-21 18:12:42 +02:00
parent 0441c9c78b
commit 398fd613ec
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108

View File

@ -24,24 +24,24 @@ public sealed class TemporaryChatService(ILogger<TemporaryChatService> logger, S
return;
}
await this.StartMaintenance();
this.StartMaintenance();
while (!stoppingToken.IsCancellationRequested)
{
await Task.Delay(CHECK_INTERVAL, stoppingToken);
await this.StartMaintenance();
this.StartMaintenance();
}
}
#endregion
private Task StartMaintenance()
private void StartMaintenance()
{
logger.LogInformation("Starting maintenance of temporary chat storage.");
var temporaryDirectories = Path.Join(SettingsManager.DataDirectory, "tempChats");
if(!Directory.Exists(temporaryDirectories))
{
logger.LogWarning("Temporary chat storage directory does not exist. End maintenance.");
return Task.CompletedTask;
return;
}
foreach (var tempChatDirPath in Directory.EnumerateDirectories(temporaryDirectories))
@ -71,7 +71,6 @@ public sealed class TemporaryChatService(ILogger<TemporaryChatService> logger, S
}
logger.LogInformation("Finished maintenance of temporary chat storage.");
return Task.CompletedTask;
}
public static void Initialize()