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

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