Skip to content

Instantly share code, notes, and snippets.

@rahulsahay19
Last active January 11, 2021 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rahulsahay19/f349096a47101c2359242cca3eaf0cca to your computer and use it in GitHub Desktop.
Save rahulsahay19/f349096a47101c2359242cca3eaf0cca to your computer and use it in GitHub Desktop.
Policies.cs
private static IAsyncPolicy<HttpResponseMessage> GetRetryPolicy()
{
return HttpPolicyExtensions.HandleTransientHttpError()
.WaitAndRetryAsync(5,
retryAttempt => TimeSpan.FromMilliseconds(Math.Pow(2, retryAttempt) * 1000),
(_, waitingTime) =>
{
Console.WriteLine("Retrying.....");
});
}
private static IAsyncPolicy<HttpResponseMessage> GetCircuitBreakerPolicy()
{
return HttpPolicyExtensions
.HandleTransientHttpError()
.CircuitBreakerAsync(3, TimeSpan.FromSeconds(10));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment