using LCU.Api.Internal.Dispatcher.Services.DispatcherOperationServices; using LCU.Api.Internal.MaidBotLib.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 JobFailureConsumer : IConsumer { private readonly IServiceScopeFactory _scopeFactory; public JobFailureConsumer(IServiceScopeFactory scopeFactory) { _scopeFactory = scopeFactory; } public async Task Consume(ConsumeContext context) { try { using var scope = _scopeFactory.CreateAsyncScope(); var performanceMonitor = new PerformanceMonitor("DispatcherJobFailureConsumerMonitor", Guid.NewGuid()); await scope.ServiceProvider.GetRequiredService().HandleJobFailureRequest(context.Message); performanceMonitor.LogPerformance((new Dictionary(){ {"JobId", context.Message.JobId.ToString()}, {"WorkItemId", context.Message.WorkItemId.ToString()} })); } catch (ServiceException serviceException) { Log.ForContext(Enum.GetName(typeof(PropertyEnum), PropertyEnum.Group), Enum.GetName(typeof(GroupEnum), GroupEnum.ITDevelopment)) .Error(serviceException, $"Dispatcher Job Failure. " + $"The Dispatcher Job Failure Request is placed on LCU.Dispatcher.JobFailure_error."); throw; } catch (Exception exception) { Log.ForContext(Enum.GetName(typeof(PropertyEnum), PropertyEnum.Group), Enum.GetName(typeof(GroupEnum), GroupEnum.ITDevelopment)) .Fatal(exception, $"Unexpected Dispatcher Job Failure. " + $"The Dispatcher Job Failure Request is placed on LCU.Dispatcher.JobFailure_error."); throw; } } } }