using System.Threading; using LCU.API.Internal.Operations.IncentiveApi.Configuration; using LCU.Api.Internal.MaidBotLib.Models; using LCU.Library.Internal.Exceptions; using LCU.Library.Internal.IncentiveApiModels.Requests; using MassTransit; namespace LCU.API.Internal.Operations.IncentiveApi.Services.QueueServices { public class QueueNightlyIncentiveProcessesService : IQueueNightlyIncentiveProcessesService { private readonly ISendEndpoint _sendEndpoint; public QueueNightlyIncentiveProcessesService(IBusControl busControl, ReceiveEndpointConfigurations receiveEndpointConfigurations) { _sendEndpoint = busControl.GetSendEndpoint(receiveEndpointConfigurations.NightlyIncentiveProcessesEndpoint.ReceiveEndpointUri).Result; } public async Task QueueNightlyIncentiveProcess(NightlyIncentiveProcessRequest request) { try { var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(30)); await _sendEndpoint.Send(request, cancellationTokenSource.Token); } catch (Exception exception) { var message = "Failed to Queue Nightly Incentive Process."; Log.ForContext(Enum.GetName(typeof(PropertyEnum), PropertyEnum.Group), Enum.GetName(typeof(GroupEnum), GroupEnum.ITDevelopment)) .Fatal(exception, message); throw new ServiceException(message); } } } }