forked from Kieran/void.cat
Catch exceptions in expired deletion service
This commit is contained in:
parent
de975be92f
commit
1c370dfd24
@ -22,28 +22,36 @@ public sealed class DeleteExpiredFiles : BackgroundService
|
|||||||
{
|
{
|
||||||
while (!stoppingToken.IsCancellationRequested)
|
while (!stoppingToken.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
using var scope = _scopeFactory.CreateScope();
|
try
|
||||||
var metadata = scope.ServiceProvider.GetRequiredService<IFileMetadataStore>();
|
|
||||||
var fileInfoManager = scope.ServiceProvider.GetRequiredService<FileInfoManager>();
|
|
||||||
var fileStoreFactory = scope.ServiceProvider.GetRequiredService<FileStoreFactory>();
|
|
||||||
|
|
||||||
var files = await metadata.ListFiles<SecretFileMeta>(new(0, int.MaxValue));
|
|
||||||
await foreach (var f in files.Results.WithCancellation(stoppingToken))
|
|
||||||
{
|
{
|
||||||
try
|
using var scope = _scopeFactory.CreateScope();
|
||||||
{
|
var metadata = scope.ServiceProvider.GetRequiredService<IFileMetadataStore>();
|
||||||
if (f.Expires < DateTime.Now)
|
var fileInfoManager = scope.ServiceProvider.GetRequiredService<FileInfoManager>();
|
||||||
{
|
var fileStoreFactory = scope.ServiceProvider.GetRequiredService<FileStoreFactory>();
|
||||||
await fileStoreFactory.DeleteFile(f.Id);
|
|
||||||
await fileInfoManager.Delete(f.Id);
|
|
||||||
|
|
||||||
_logger.LogInformation("Deleted file: {Id}", f.Id);
|
var files = await metadata.ListFiles<SecretFileMeta>(new(0, int.MaxValue));
|
||||||
|
await foreach (var f in files.Results.WithCancellation(stoppingToken))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (f.Expires < DateTime.Now)
|
||||||
|
{
|
||||||
|
await fileStoreFactory.DeleteFile(f.Id);
|
||||||
|
await fileInfoManager.Delete(f.Id);
|
||||||
|
|
||||||
|
_logger.LogInformation("Deleted file: {Id}", f.Id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Failed to delete file: {Id}", f.Id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
}
|
||||||
_logger.LogError(ex, "Failed to delete file: {Id}", f.Id);
|
catch (Exception ex)
|
||||||
}
|
{
|
||||||
|
_logger.LogError(ex, "Failed to run delete expired file services");
|
||||||
}
|
}
|
||||||
|
|
||||||
await Task.Delay(TimeSpan.FromMinutes(5), stoppingToken);
|
await Task.Delay(TimeSpan.FromMinutes(5), stoppingToken);
|
||||||
|
Loading…
Reference in New Issue
Block a user