Adding MaidBotApi
This commit is contained in:
+40
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using MassTransit;
|
||||
using Serilog;
|
||||
using LCU.Library.Internal.Exceptions;
|
||||
using LCU.Api.Internal.MaidBotLib.Models;
|
||||
using LCU.Api.Internal.MaidBotApi.Services;
|
||||
namespace LCU.Api.Internal.MaidBotApi.Consumers;
|
||||
|
||||
public class LoggingEventConsumer : IConsumer<EventLog>
|
||||
{
|
||||
private readonly IServiceScopeFactory _scopeFactory;
|
||||
|
||||
public LoggingEventConsumer(IServiceScopeFactory scopeFactory)
|
||||
{
|
||||
_scopeFactory = scopeFactory;
|
||||
}
|
||||
|
||||
public async Task Consume(ConsumeContext<EventLog> context)
|
||||
{
|
||||
try
|
||||
{
|
||||
using var scope = _scopeFactory.CreateScope();
|
||||
await Task.Run(async () => await scope.ServiceProvider.GetRequiredService<IEventLogService>().HandleIncomingEventLog(context.Message));
|
||||
}
|
||||
catch (ServiceException serviceException)
|
||||
{
|
||||
Log.Fatal(serviceException, $"Handle Incoming EventLog Failure. " +
|
||||
$"The Handle Incoming EventLog is placed on LCU.MaidBot_error.");
|
||||
throw;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.Fatal(exception, $"Unexpected Handle Incoming EventLog Failure. " +
|
||||
$"The Handle Incoming EventLog is placed on LCU.MaidBot_error.");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user