try catch on cleanup task

This commit is contained in:
rootdarkarchon
2023-01-27 02:46:13 +01:00
parent 91b98d060a
commit 6560b1d70d

View File

@@ -44,6 +44,8 @@ public class FileCleanupService : IHostedService
_logger.LogInformation("Starting periodic cleanup task");
while (!ct.IsCancellationRequested)
{
try
{
DirectoryInfo dir = new(_cacheDir);
var allFiles = dir.GetFiles("*", SearchOption.AllDirectories);
@@ -63,6 +65,11 @@ public class FileCleanupService : IHostedService
await dbContext.SaveChangesAsync(ct).ConfigureAwait(false);
}
}
catch (Exception e)
{
_logger.LogError(e, "Error during cleanup task");
}
var now = DateTime.Now;
TimeOnly currentTime = new(now.Hour, now.Minute, now.Second);