Esempio n. 1
0
        private async Task MakeRequestAsync(IWebhookEventEntity @event)
        {
            try
            {
                var response = await webhookSender.SendAsync(@event.Job);

                Instant?nextCall = null;

                if (response.Result != WebhookResult.Success)
                {
                    var now = clock.GetCurrentInstant();

                    switch (@event.NumCalls)
                    {
                    case 0:
                        nextCall = now.Plus(Duration.FromMinutes(5));
                        break;

                    case 1:
                        nextCall = now.Plus(Duration.FromHours(1));
                        break;

                    case 2:
                        nextCall = now.Plus(Duration.FromHours(5));
                        break;

                    case 3:
                        nextCall = now.Plus(Duration.FromHours(6));
                        break;
                    }
                }

                await Task.WhenAll(
                    webhookRepository.TraceSentAsync(@event.Job.WebhookId, response.Result, response.Elapsed),
                    webhookEventRepository.TraceSentAsync(@event.Id, response.Dump, response.Result, response.Elapsed, nextCall));
            }
            catch (Exception ex)
            {
                log.LogError(ex, w => w
                             .WriteProperty("action", "SendWebhookEvent")
                             .WriteProperty("status", "Failed"));

                throw;
            }
        }
Esempio n. 2
0
 private void SetupSender(IWebhookEventEntity @event, string requestDump, WebhookResult requestResult, TimeSpan requestTime)
 {
     A.CallTo(() => webhookSender.SendAsync(@event.Job))
     .Returns(Task.FromResult((requestDump, requestResult, requestTime)));
 }