Fauna v10 .NET/C# Driver 1.0.1
 
Loading...
Searching...
No Matches
RetryConfiguration.cs
Go to the documentation of this file.
1using System.Net;
2using System.Net.Sockets;
3using Polly;
4
5namespace Fauna.Core;
6
11{
12
16 public AsyncPolicy<HttpResponseMessage> RetryPolicy { get; set; }
17
18
24 public RetryConfiguration(int retryCount, TimeSpan maxBackoff)
25 {
26 RetryPolicy = Policy
27 .Handle<HttpRequestException>()
28 .Or<SocketException>()
29 .Or<IOException>()
30 .Or<InvalidOperationException>()
31 .OrResult<HttpResponseMessage>(r => r.StatusCode == HttpStatusCode.TooManyRequests)
32 .WaitAndRetryAsync(retryCount, attempt =>
33 {
34 int calculated = (int)Math.Floor(Math.Pow(2, attempt));
35 int backoff = calculated > maxBackoff.Seconds ? maxBackoff.Seconds : calculated;
36 return TimeSpan.FromSeconds(backoff);
37 });
38 }
39}
A class representing a retry configuration for queries.
RetryConfiguration(int retryCount, TimeSpan maxBackoff)
Creates a new RetryConfiguration instance.
AsyncPolicy< HttpResponseMessage > RetryPolicy
Gets the retry policy.