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 QueueCreditCardImportService : IQueueCreditCardImportService { private readonly ISendEndpoint _sendEndpoint; public QueueCreditCardImportService(IBusControl busControl, ReceiveEndpointConfigurations receiveEndpointConfigurations) { _sendEndpoint = busControl.GetSendEndpoint(receiveEndpointConfigurations.ImportCreditCardSalesEndpoint.ReceiveEndpointUri).Result; } public async Task QueueCreditCardSalesImport(ImportCreditCardSalesRequest request) { try { var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(30)); await _sendEndpoint.Send(request, cancellationTokenSource.Token); } catch (Exception exception) { var message = "Failed to Queue Credit Card Sales Import."; Log.ForContext(Enum.GetName(typeof(PropertyEnum), PropertyEnum.Group), Enum.GetName(typeof(GroupEnum), GroupEnum.ITDevelopment)) .Fatal(exception, message); throw new ServiceException(message); } } } }