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 { private readonly IServiceScopeFactory _scopeFactory; public DetermineOperationConsumer(IServiceScopeFactory scopeFactory) { _scopeFactory = scopeFactory; } public async Task Consume(ConsumeContext context) { try { using var scope = _scopeFactory.CreateAsyncScope(); var performanceMonitor = new PerformanceMonitor("DispatcherDetermineOperationConsumerMonitor", Guid.NewGuid()); await scope.ServiceProvider.GetRequiredService().HandleDetermineOperationRequest(context.Message); performanceMonitor.LogPerformance((new Dictionary(){ {"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; } } } }