using System; using System.Threading; using System.Threading.Tasks; using MassTransit; using Serilog; using LCU.Api.Internal.MaidBotLib.Models; using LCU.Library.Internal.Exceptions; using LCU.Library.Internal.LcuMassTransitModels; namespace LCU.Api.Internal.MaidBotApi.Services; public class QueueEventLogService : IQueueEventLogService { private readonly ISendEndpoint _sendEndpoint; public QueueEventLogService(IBusControl busControl, ReceiveEndpointConfiguration receiveEndpointConfiguration) { _sendEndpoint = busControl.GetSendEndpoint(receiveEndpointConfiguration.ReceiveEndpointUri).Result; } public async Task QueueEventLog(EventLog request) { try { var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(30)); await _sendEndpoint.Send(request, cancellationTokenSource.Token); } catch (Exception exception) { Log.ForContext(Enum.GetName(typeof(PropertyEnum), PropertyEnum.Group), Enum.GetName(typeof(GroupEnum), GroupEnum.ITDevelopment)) .Fatal(exception, "Failed to Queue EventLog Request."); throw new ServiceException("Failed to Queue EventLog Request."); } } }