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

58 lines
2.7 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 SendErroredJobAlertConsumer : IConsumer<Batch<BatchedErroredJobAlertRequest>>
{
private readonly IServiceScopeFactory _scopeFactory;
public SendErroredJobAlertConsumer(IServiceScopeFactory scopeFactory)
{
_scopeFactory = scopeFactory;
}
public async Task Consume(ConsumeContext<Batch<BatchedErroredJobAlertRequest>> context)
{
try
{
using var scope = _scopeFactory.CreateAsyncScope();
var performanceMonitor = new PerformanceMonitor("DispatcherBatchErroredJobsConsumerMonitor", Guid.NewGuid());
var batchedErroredJobAlertRequestlist = new List<BatchedErroredJobAlertRequest>();
for (int index = 0; index < context.Message.Length; index++)
{
ConsumeContext<BatchedErroredJobAlertRequest> messageContext = context.Message[index];
batchedErroredJobAlertRequestlist.Add(messageContext.Message);
}
await scope.ServiceProvider.GetRequiredService<ISendErroredJobAlertService>().HandleSendingErroredJobAlerts(batchedErroredJobAlertRequestlist);
performanceMonitor.LogPerformance((new Dictionary<string, string>(){
{"NumberOfBatchedErrors", batchedErroredJobAlertRequestlist.Count().ToString()}
}));
}
catch (ServiceException serviceException)
{
Log.ForContext(Enum.GetName(typeof(PropertyEnum), PropertyEnum.Group),
Enum.GetName(typeof(GroupEnum), GroupEnum.ITDevelopment))
.Error(serviceException, $"Dispatcher Send Errored Job Alert. " +
$"The Dispatcher Send Errored Job Alert Request is placed on LCU.Dispatcher.SendErroredJobAlert_error.");
throw;
}
catch (Exception exception)
{
Log.ForContext(Enum.GetName(typeof(PropertyEnum), PropertyEnum.Group),
Enum.GetName(typeof(GroupEnum), GroupEnum.ITDevelopment))
.Fatal(exception, $"Unexpected Dispatcher Send Errored Job Alert. " +
$"The Dispatcher Send Errored Job Alert Request is placed on LCU.Dispatcher.SendErroredJobAlert_error.");
throw;
}
}
}
}