This commit is contained in:
Zeeshaun
2026-03-24 15:26:03 -05:00
parent 1e5beb292a
commit 9cc87337b8
333 changed files with 17931 additions and 0 deletions
@@ -0,0 +1,47 @@
using LCU.Api.Internal.Dispatcher.Services.DispatcherOperationServices;
using LCU.Api.Internal.MaidBotLib.Models;
using LCU.Library.Internal.Logging.Performance;
using MassTransit;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using System.Collections.Generic;
using ApiResponse = LCU.Library.Internal.ApiResponse.Models.Response;
namespace LCU.Api.Internal.Dispatcher.Consumers;
public class CompletionConsumer : IConsumer<ApiResponse>
{
private readonly IServiceScopeFactory _scopeFactory;
public CompletionConsumer(IServiceScopeFactory scopeFactory)
{
_scopeFactory = scopeFactory;
}
public async Task Consume(ConsumeContext<ApiResponse> context)
{
try
{
using var scope = _scopeFactory.CreateAsyncScope();
var dispatcherReturnResponse = JsonConvert.DeserializeObject<DispatcherReturnResponse>(context.Message.ResponsePayload);
var performanceMonitor = new PerformanceMonitor("DispatcherCompletionConsumerMonitor",
Guid.NewGuid());
await scope.ServiceProvider.GetRequiredService<ICompletionService>().HandleCompletionRequest(context.Message);
performanceMonitor.LogPerformance((new Dictionary<string, string>(){
{"WorkItemId", dispatcherReturnResponse.WorkItemId.ToString()}
}));
}
catch (ServiceException serviceException)
{
Log.ForContext(Enum.GetName(typeof(PropertyEnum), PropertyEnum.Group),
Enum.GetName(typeof(GroupEnum), GroupEnum.ITDevelopment))
.Error(serviceException, $"Dispatcher Completion Failure. " +
$"The Dispatcher Completion Request is placed on LCU.Dispatcher.Completion_error.");
return;
}
catch (Exception exception)
{
Log.Fatal(exception, $"Unexpected Failure");
}
}
}
@@ -0,0 +1,52 @@
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;
}
}
}
}
@@ -0,0 +1,47 @@
using MassTransit;
using Microsoft.Extensions.DependencyInjection;
using LCU.Api.Internal.MaidBotLib.Models;
using LCU.Api.Internal.Dispatcher.Services.DispatcherOperationServices;
using System.Collections.Generic;
using LCU.Library.Internal.Logging.Performance;
namespace LCU.Api.Internal.Dispatcher.Consumers;
public class ExecutionConsumer : IConsumer<WorkItemExecution>
{
private readonly IServiceScopeFactory _scopeFactory;
public ExecutionConsumer(IServiceScopeFactory scopeFactory)
{
_scopeFactory = scopeFactory;
}
public async Task Consume(ConsumeContext<WorkItemExecution> context)
{
try
{
using var scope = _scopeFactory.CreateAsyncScope();
var performanceMonitor = new PerformanceMonitor("DispatcherExecutionConsumerMonitor", Guid.NewGuid());
await scope.ServiceProvider.GetRequiredService<IExecutionService>().HandleExecutionRequest(context.Message);
performanceMonitor.LogPerformance((new Dictionary<string, string>(){
{"WorkItemId", context.Message.WorkItemId.ToString()},
{"WorkItemExecutionId", context.Message.WorkItemExecutionId.ToString()}
}));
}
catch (ServiceException serviceException)
{
Log.ForContext(Enum.GetName(typeof(PropertyEnum), PropertyEnum.Group),
Enum.GetName(typeof(GroupEnum), GroupEnum.ITDevelopment))
.Error(serviceException, $"Dispatcher Execution Failure. " +
$"The Dispatcher Execution Request is placed on LCU.Dispatcher.Execution_error.");
throw;
}
catch (Exception exception)
{
Log.ForContext(Enum.GetName(typeof(PropertyEnum), PropertyEnum.Group),
Enum.GetName(typeof(GroupEnum), GroupEnum.ITDevelopment))
.Fatal(exception, $"Unexpected Dispatcher Execution Failure. " +
$"The Dispatcher Execution Request is placed on LCU.Dispatcher.Execution_error.");
throw;
}
}
}
@@ -0,0 +1,50 @@
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;
}
}
}
}
@@ -0,0 +1,57 @@
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;
}
}
}
}