Files
monorepo/LCU.API.Operations.IncentiveAPI/LCU.API.Internal.Operations.IncentiveApi/Consumers/ActionCreditCardConsumer.cs
T
2026-03-17 09:53:09 -05:00

46 lines
1.9 KiB
C#

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