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