Esempio n. 1
0
        private List <CdcTableTypeModel> GetCdcDataModels(QaConfigCustomer customer, out string toLsn)
        {
            List <CdcTableTypeModel> result;

            using (var ts = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions {
                IsolationLevel = IsolationLevel.ReadCommitted
            }))
                using (new QPConnectionScope(customer.ConnectionString, customer.DbType))
                {
                    var fromLsn = _cdcImportService.GetLastExecutedLsn(Settings.Default.HttpEndpoint);
                    toLsn  = _cdcImportService.GetMaxLsn();
                    result = _cdcImportService.GetCdcDataFromTables(fromLsn, toLsn);
                    ts.Complete();
                }

            return(result);
        }
Esempio n. 2
0
        private int ProcessCustomer(QaConfigCustomer customer)
        {
            var customerDbScheduler = _unityContainer.Resolve <DbScheduler>(
                new ParameterOverride("customer", customer),
                new ParameterOverride("connectionString", customer.ConnectionString),
                new ParameterOverride("dbType", customer.DbType)
                );

            QPContext.CurrentCustomerCode = customer.CustomerName;

            Logger.Trace()
            .Message("Processing customer code: {customerCode}", customer.CustomerName)
            .Write();

            customerDbScheduler.Run();
            return(customerDbScheduler.GetTasksCountToProcessAtSpecificDateTime(DateTime.Now.Add(_tasksQueueCheckShiftTime)));
        }
Esempio n. 3
0
        private async Task <Tuple <List <int>, List <int> > > ProcessCustomer(QaConfigCustomer customer, CancellationToken token)
        {
            using (new QPConnectionScope(customer.ConnectionString, customer.DbType))
            {
                var sentNotificationIds     = new List <int>();
                var unsentNotificationIds   = new List <int>();
                var notificationsViewModels = GetPendingNotificationsViewModels();
                foreach (var notificationVm in notificationsViewModels)
                {
                    if (token.IsCancellationRequested)
                    {
                        break;
                    }

                    try
                    {
                        var notificationIdsStatus = await SendNotificationData(notificationVm, customer.CustomerName);

                        sentNotificationIds.AddRange(notificationIdsStatus.Item1);
                        unsentNotificationIds.AddRange(notificationIdsStatus.Item2);
                    }
                    catch (Exception ex)
                    {
                        unsentNotificationIds.AddRange(notificationVm.NotificationsIds);
                        Logger.Error(ex,
                                     "Exception while sending event {eventName} to {url} for customer code {customerCode}",
                                     notificationVm.NotificationModel.EventName,
                                     notificationVm.NotificationModel.Url,
                                     customer.CustomerName);
                    }
                }

                UpdateDbNotificationsData(sentNotificationIds, unsentNotificationIds);
                return(Tuple.Create(sentNotificationIds, unsentNotificationIds));
            }
        }
Esempio n. 4
0
 public PublishingTaskScheduler(QaConfigCustomer customer, IArticlePublishingSchedulerService publishingService)
 {
     _customer          = customer;
     _publishingService = publishingService;
 }
Esempio n. 5
0
 public RecurringTaskScheduler(QaConfigCustomer customer, IArticleRecurringSchedulerService recurringService)
 {
     _customer         = customer;
     _recurringService = recurringService;
 }
Esempio n. 6
0
 public OnetimeTaskScheduler(QaConfigCustomer customer, IArticleOnetimeSchedulerService onetimeService)
 {
     _customer       = customer;
     _onetimeService = onetimeService;
 }
Esempio n. 7
0
 private static void SetIsCustomerNotificationQueueEmpty(QaConfigCustomer customer, bool isNotificationQueueEmpty)
 {
     CustomersDictionary.TryUpdate(customer, isNotificationQueueEmpty, !isNotificationQueueEmpty);
 }
Esempio n. 8
0
 public static void SetCustomerNotificationQueueNotEmpty(QaConfigCustomer customer)
 {
     SetIsCustomerNotificationQueueEmpty(customer, false);
 }
Esempio n. 9
0
        private async Task <(List <int> sentNotificationIds, List <int> unsentNotificationIds, string lastExceptionMessage)> ProcessTarantoolNotifications(QaConfigCustomer customer, CancellationToken token)
        {
            var notificationDtos    = GetPendingNotifications(CdcProviderName.Tarantool.ToString()).ToList();
            var sentNotificationIds = new List <int>();

            string httpNotSendedReason = null;
            var    notSendedDtosQueue  = new Queue <SystemNotificationDto>(notificationDtos);

            while (notSendedDtosQueue.Any() && token.IsCancellationRequested)
            {
                var dto = notSendedDtosQueue.Peek();
                Task <HttpResponseMessage> responseMessage = null;

                try
                {
                    responseMessage = PushDataToHttpChannel(dto.Url, dto.Json, customer.CustomerName);
                    var response = await responseMessage.ReceiveJson <JSendResponse>();

                    if (response.Status != JSendStatus.Success || response.Code != 200)
                    {
                        httpNotSendedReason = response.ToJsonLog();
                        Logger.Warn($"Http push notification response was failed for customer code: {customer.CustomerName}: {response.ToJsonLog()}");
                        break;
                    }

                    sentNotificationIds.Add(notSendedDtosQueue.Dequeue().Id);
                    Logger.Trace($"Http push notification was pushed successfuly for customer code: {customer.CustomerName}: {response.ToJsonLog()}");
                }
                catch (Exception ex) when(ex is JsonReaderException)
                {
                    var responseBodyMessage = $"Response body: {await responseMessage.ReceiveString()}.";

                    httpNotSendedReason = $"Exception while parsing response. {responseBodyMessage}";
                    Logger.Error(ex, $"Exception while parsing response for customer code: {customer.CustomerName}. {responseBodyMessage} Notification: {dto.ToJsonLog()}");
                    break;
                }
                catch (Exception ex)
                {
                    httpNotSendedReason = ex.Dump();
                    Logger.Error(ex, $"Exception while sending notification for customer code: {customer.CustomerName}. Notification: {dto.ToJsonLog()}");
                    break;
                }
            }

            return(sentNotificationIds, notSendedDtosQueue.Select(dto => dto.Id).ToList(), httpNotSendedReason);
        }
Esempio n. 10
0
        private async Task <(List <int> sentNotificationIds, List <int> unsentNotificationIds, string lastExceptionMessage)> ProcessElasticNotifications(QaConfigCustomer customer, CancellationToken token)
        {
            var notificationDtos    = GetPendingNotifications(CdcProviderName.Elastic.ToString());
            var sentNotificationIds = new List <int>();

            string httpNotSendedReason = null;
            var    notSendedDtosQueue  = new Queue <SystemNotificationDto>(notificationDtos);

            while (notSendedDtosQueue.Any() && token.IsCancellationRequested)
            {
                var dto = notSendedDtosQueue.Peek();
                try
                {
                    var responseMessage = PushDataToHttpChannel(dto.Url, dto.Json, customer.CustomerName);
                    var response        = await responseMessage.ReceiveString();

                    if (!(await responseMessage).IsSuccessStatusCode)
                    {
                        httpNotSendedReason = response;
                        Logger.Warn($"Http push notification response was failed for customer code: {customer.CustomerName}: {response}");
                        break;
                    }

                    sentNotificationIds.Add(notSendedDtosQueue.Dequeue().Id);
                    Logger.Trace($"Http push notification was pushed successfuly for customer code: {customer.CustomerName}: {response}");
                }
                catch (Exception ex)
                {
                    httpNotSendedReason = ex.Dump();
                    Logger.Error(ex, $"Exception while sending notification for customer code: {customer.CustomerName}. Notification: {dto.ToJsonLog()}");
                    break;
                }
            }

            return(sentNotificationIds, notSendedDtosQueue.Select(dto => dto.Id).ToList(), httpNotSendedReason);
        }
        private async Task <(List <int> prtgSentNotificationIds, List <int> prtgUnsentNotificationIds)> ProcessCustomer(QaConfigCustomer customer, CancellationToken token)
        {
            var prtgSentNotificationIds   = new List <int>();
            var prtgUnsentNotificationIds = new List <int>();

            var tarantoolSentUnsentTuple = await ProcessTarantoolNotifications(customer, token);

            prtgSentNotificationIds.AddRange(tarantoolSentUnsentTuple.sentNotificationIds);
            prtgUnsentNotificationIds.AddRange(tarantoolSentUnsentTuple.unsentNotificationIds);

            var elasticSentUnsentTuple = await ProcessElasticNotifications(customer, token);

            prtgSentNotificationIds.AddRange(elasticSentUnsentTuple.sentNotificationIds);
            prtgUnsentNotificationIds.AddRange(elasticSentUnsentTuple.unsentNotificationIds);

            UpdateDbNotificationsData(customer.ConnectionString, tarantoolSentUnsentTuple);
            UpdateDbNotificationsData(customer.ConnectionString, elasticSentUnsentTuple);

            return(prtgSentNotificationIds, prtgUnsentNotificationIds);
        }