Skip to content

Commit 5b92609

Browse files
committed
Added Polly code for retry logging
1 parent 424167b commit 5b92609

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed
Binary file not shown.

MachineIntelligenceTPLDataFlows/Policies/HttpPolicies.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Polly;
1+
using Microsoft.Extensions.Logging;
2+
using Polly;
23
using Polly.Extensions.Http;
34
using System;
45
using System.Net.Http;
@@ -11,8 +12,15 @@ public static Polly.Retry.AsyncRetryPolicy<HttpResponseMessage> GetRetryPolicy()
1112
{
1213
var retryPolicy = HttpPolicyExtensions
1314
.HandleTransientHttpError() // HttpRequestException, 5XX and 408
15+
.OrResult(response => response.StatusCode == System.Net.HttpStatusCode.NotFound) // Handle NotFound 404
1416
.OrResult(response => response.StatusCode == System.Net.HttpStatusCode.TooManyRequests) // Handle too many requests 429
15-
.WaitAndRetryAsync(4, retryAttempt => TimeSpan.FromSeconds(Math.Pow(3, retryAttempt)));
17+
.WaitAndRetryAsync(4, retryAttempt => TimeSpan.FromSeconds(Math.Pow(3, retryAttempt)),
18+
onRetry: (response, calculatedWaitDuration) =>
19+
{
20+
Console.WriteLine($"Failed attempt. Waited for {calculatedWaitDuration}");// Retrying. {response.Exception.Message} - {response.Exception.StackTrace}");
21+
}
22+
);
23+
1624

1725
return retryPolicy;
1826
}

0 commit comments

Comments
 (0)