Files
monorepo/LCU.API.Internal.Dispatcher/LCU.Api.Internal.Dispatcher/Consumers/DetermineOperationConsumer.cs
T
2026-03-24 15:26:03 -05:00

53 lines
2.6 KiB
C#

using LCU.Api.Internal.Dispatcher.Services.DispatcherOperationServices;
using LCU.Api.Internal.MaidBotLib.Models;
using LCU.Library.Internal.DispatcherModels.Models;
using LCU.Library.Internal.DispatcherModels.Models.Requests;
using LCU.Library.Internal.Logging.Performance;
using MassTransit;
using Microsoft.Extensions.DependencyInjection;
using System.Collections.Generic;
namespace LCU.Api.Internal.Dispatcher.Consumers
{
public class DetermineOperationConsumer : IConsumer<DetermineOperationRequest>
{
private readonly IServiceScopeFactory _scopeFactory;
public DetermineOperationConsumer(IServiceScopeFactory scopeFactory)
{
_scopeFactory = scopeFactory;
}
public async Task Consume(ConsumeContext<DetermineOperationRequest> context)
{
try
{
using var scope = _scopeFactory.CreateAsyncScope();
var performanceMonitor = new PerformanceMonitor("DispatcherDetermineOperationConsumerMonitor", Guid.NewGuid());
await scope.ServiceProvider.GetRequiredService<IDetermineOperationService>().HandleDetermineOperationRequest(context.Message);
performanceMonitor.LogPerformance((new Dictionary<string, string>(){
{"JobId", context.Message.CurrentJob.JobId.ToString()},
{"WorkItemId", context.Message.CurrentWorkItem.WorkItemId.ToString()},
{"WorkItemExecutionId", context.Message.CurrentWorkItem?.CurrentWorkItemExecution?.WorkItemExecutionId.ToString()}
}));
}
catch (ServiceException serviceException)
{
Log.ForContext(Enum.GetName(typeof(PropertyEnum), PropertyEnum.Group),
Enum.GetName(typeof(GroupEnum), GroupEnum.ITDevelopment))
.Error(serviceException, $"Dispatcher Determine Operation Failure. " +
$"The Dispatcher Determine Operation Request is placed on LCU.Dispatcher.DetermineOperation_error.");
throw;
}
catch (Exception exception)
{
Log.ForContext(Enum.GetName(typeof(PropertyEnum), PropertyEnum.Group),
Enum.GetName(typeof(GroupEnum), GroupEnum.ITDevelopment))
.Fatal(exception, $"Unexpected Dispatcher Determine Operation Failure. " +
$"The Dispatcher Determine Operation Request is placed on LCU.Dispatcher.DetermineOperation_error.");
throw;
}
}
}
}