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