44 lines
1.8 KiB
C#
44 lines
1.8 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;
|
|
namespace LCU.API.Internal.DocumentIngestor.Consumers;
|
|
|
|
public class IngestorIndexConsumer : IConsumer<IngestorRequest>
|
|
{
|
|
private readonly IServiceScopeFactory _scopeFactory;
|
|
|
|
public IngestorIndexConsumer(IServiceScopeFactory scopeFactory)
|
|
{
|
|
_scopeFactory = scopeFactory;
|
|
}
|
|
|
|
public async Task Consume(ConsumeContext<IngestorRequest> context)
|
|
{
|
|
try
|
|
{
|
|
Log.Debug("Starting HandleIngestion.");
|
|
using var scope = _scopeFactory.CreateScope();
|
|
await Task.Run(async () => await scope.ServiceProvider.GetRequiredService<IIndexService>().HandleIngestion(context.Message));
|
|
Log.Debug("Starting HandleIngestion.");
|
|
}
|
|
catch (ServiceException serviceException)
|
|
{
|
|
Log.ForContext(Enum.GetName(typeof(PropertyEnum), PropertyEnum.Group),
|
|
Enum.GetName(typeof(GroupEnum), GroupEnum.ITDevelopment))
|
|
.Error(serviceException, $"Document Ingestor Failure. " +
|
|
$"The Document Ingestor Request is placed on LCU.DocumentIngestor.Indexing_error.");
|
|
throw;
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
Log.ForContext(Enum.GetName(typeof(PropertyEnum), PropertyEnum.Group),
|
|
Enum.GetName(typeof(GroupEnum), GroupEnum.ITDevelopment))
|
|
.Fatal(exception, $"Unexpected Document Ingestor Failure. " +
|
|
$"The Document Upload Request is placed on LCU.DocumentIngestor.Indexing_error.");
|
|
throw;
|
|
}
|
|
}
|
|
} |