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.Payout; using MassTransit; namespace LCU.API.Internal.Operations.IncentiveApi.Consumers; public class PayoutIncentiveConsumer : IConsumer { private readonly IServiceScopeFactory _scopeFactory; public PayoutIncentiveConsumer(IServiceScopeFactory scopeFactory) { _scopeFactory = scopeFactory; } public async Task Consume(ConsumeContext context) { try { Log.Information("Starting Payout Incentive Process."); using var scope = _scopeFactory.CreateScope(); await Task.Run(async () => await scope.ServiceProvider.GetRequiredService().RunMonthlyIncentivePayouts(context.Message)); Log.Information("Finished Payout Incentive Process."); } catch (ServiceException serviceException) { Log.ForContext(Enum.GetName(typeof(PropertyEnum), PropertyEnum.Group), Enum.GetName(typeof(GroupEnum), GroupEnum.ITDevelopment)) .Error(serviceException, $"Payout Incentive Process Failure. " + $"The Payout Incentive Process Request is placed on LCU.IncentiveApi.PayoutIncentiveProcess_error."); throw; } catch (Exception exception) { Log.ForContext(Enum.GetName(typeof(PropertyEnum), PropertyEnum.Group), Enum.GetName(typeof(GroupEnum), GroupEnum.ITDevelopment)) .Fatal(exception, $"Payout Incentive Process Failure. " + $"The Payout Incentive Process Request is placed on LCU.IncentiveApi.PayoutIncentiveProcess_error."); throw; } } }