Files
monorepo/LCU.API.Internal.DocumentIngestor/LCU.API.Internal.DocumentIngestor/Consumers/IngestionFolderCleanUpConsumer.cs
T
2026-03-25 14:50:13 -05:00

43 lines
1.9 KiB
C#

using MassTransit;
using Serilog;
using LCU.Library.Internal.DocumentIngestorModels.Models;
using LCU.Library.Internal.Exceptions;
using LCU.Api.Internal.MaidBotLib.Models;
using LCU.API.Internal.DocumentIngestor.Services.IngestionOperationServices;
using LCU.API.Internal.DocumentIngestorLib.Exceptions;
namespace LCU.API.Internal.DocumentIngestor.Consumers;
public class IngestionFolderCleanUpConsumer : IConsumer<IngestionFolderCleanUpRequest>
{
private readonly IServiceScopeFactory _scopeFactory;
public IngestionFolderCleanUpConsumer(IServiceScopeFactory scopeFactory)
{
_scopeFactory = scopeFactory;
}
public async Task Consume(ConsumeContext<IngestionFolderCleanUpRequest> context)
{
try
{
using var scope = _scopeFactory.CreateScope();
await Task.Run(async () => await scope.ServiceProvider.GetRequiredService<IIngestionFolderCleanUpService>().HandleIngestionFolderCleanUp(context.Message));
}
catch (ServiceException serviceException)
{
Log.ForContext(Enum.GetName(typeof(PropertyEnum), PropertyEnum.Group),
Enum.GetName(typeof(GroupEnum), GroupEnum.ITDevelopment))
.Error(serviceException, $"IngestionFolderCleanUp Failure. " +
$"The Processing Request is placed on LCU.DocumentIngestor.IngestionFolderCleanUp_error.");
throw;
}
catch (Exception exception)
{
Log.ForContext(Enum.GetName(typeof(PropertyEnum), PropertyEnum.Group),
Enum.GetName(typeof(GroupEnum), GroupEnum.ITDevelopment))
.Fatal(exception, $"Unexpected IngestionFolderCleanUp Failure. " +
$"The Processing Request is placed on LCU.DocumentIngestor.IngestionFolderCleanUp_error.");
throw;
}
}
}