Files
2026-03-24 15:26:03 -05:00

51 lines
2.2 KiB
C#

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