using LCU.API.Internal.Operations.IncentiveApi.Services.Temenos; using LCU.Api.Internal.MaidBotLib.Models; using LCU.Library.Internal.IncentiveApiModels.Requests; using Microsoft.Extensions.DependencyInjection; using LCU.Library.Internal.Exceptions; using MassTransit; namespace LCU.API.Internal.Operations.IncentiveApi.Consumers; public class ImportIndirectVehicleSalesConsumer : IConsumer { private readonly IServiceScopeFactory _scopeFactory; public ImportIndirectVehicleSalesConsumer(IServiceScopeFactory scopeFactory) { _scopeFactory = scopeFactory; } public async Task Consume(ConsumeContext context) { try { Log.Debug("Starting HandleImportIndirectVehicleSales."); using var scope = _scopeFactory.CreateScope(); await Task.Run(async () => await scope.ServiceProvider.GetRequiredService().HandleImportIndirectVehicleSales(context.Message)); Log.Debug("Finished HandleImportIndirectVehicleSales."); } catch (ServiceException serviceException) { Log.ForContext(Enum.GetName(typeof(PropertyEnum), PropertyEnum.Group), Enum.GetName(typeof(GroupEnum), GroupEnum.ITDevelopment)) .Error(serviceException, $"Import Indirect Vehicle Sales Failure. " + $"The Import Indirect Vehicle Sales Request is placed on LCU.IncentiveApi.ImportIndirectVehicleSales_error."); throw; } catch (Exception exception) { Log.ForContext(Enum.GetName(typeof(PropertyEnum), PropertyEnum.Group), Enum.GetName(typeof(GroupEnum), GroupEnum.ITDevelopment)) .Fatal(exception, $"Import Indirect Vehicle Sales Failure. " + $"The Import Indirect Vehicle Sales Request is placed on LCU.IncentiveApi.ImportIndirectVehicleSales_error."); throw; } } }