Adding
This commit is contained in:
+47
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user