Exemple #1
0
        public async Task SendWebhook(IntegrationEventSubscription eventSubscription, WebhookPayload payload,
                                      IntegrationEventSubscriptionAttempt subscriptionAttempt, bool isSystemEvent, string payloadJSON)
        {
            var attemptCount = _attemptManager.SaveAndGetAttemptCount(subscriptionAttempt, eventSubscription.Max_RetryCount);

            payload.AttemptCount = attemptCount;

            if (isSystemEvent == true)//event is system event use system generated payload
            {
                payloadJSON = JsonConvert.SerializeObject(payload);
            }

            bool isSuccessful;

            try
            {
                isSuccessful = await SendWebhookAsync(payloadJSON, eventSubscription.HTTP_URL, eventSubscription);
            }
            catch (Exception exception) //an internal error occurred
            {
                throw exception;
            }

            if (!isSuccessful)
            {
                if (attemptCount > (eventSubscription.Max_RetryCount ?? 1))
                {
                    var previousAttempt = _attemptManager.GetLastAttempt(subscriptionAttempt);
                    previousAttempt.Status = "FailedFatally";
                    _attemptRepository.Update(previousAttempt);
                }
                else
                {
                    throw new Exception($"Webhook sending attempt failed.");
                }
            }
            else
            {
                var previousAttempt = _attemptManager.GetLastAttempt(subscriptionAttempt);
                previousAttempt.Status = "Completed";
                _attemptRepository.Update(previousAttempt);
            }

            return;
        }
        public async Task SendWebhook(IntegrationEventSubscription eventSubscription, WebhookPayload payload,
                                      IntegrationEventSubscriptionAttempt subscriptionAttempt)
        {
            var attemptCount = _attemptManager.SaveAndGetAttemptCount(subscriptionAttempt, eventSubscription.Max_RetryCount);

            payload.AttemptCount = attemptCount;

            bool isSuccessful;

            try
            {
                isSuccessful = await SendWebhookAsync(payload, eventSubscription.HTTP_URL, eventSubscription);
            }
            catch (Exception exception) //an internal error occurred
            {
                throw exception;
            }

            if (!isSuccessful)
            {
                if (attemptCount > eventSubscription.Max_RetryCount)
                {
                    var previousAttempt = _attemptManager.GetLastAttempt(subscriptionAttempt);
                    previousAttempt.Status = "FailedFatally";
                    _attemptRepository.Update(previousAttempt);
                }
                else
                {
                    throw new Exception($"Webhook sending attempt failed.");
                }
            }
            else
            {
                var previousAttempt = _attemptManager.GetLastAttempt(subscriptionAttempt);
                previousAttempt.Status = "Completed";
                _attemptRepository.Update(previousAttempt);
            }

            return;
        }