This repository has been archived by the owner on Jul 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathRetryPolicy.cs
46 lines (40 loc) · 1.56 KB
/
RetryPolicy.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System.Collections.Generic;
using System.Net;
namespace AzureKeyVaultRecoverySamples
{
/// <summary>
/// Models a policy for retrying an http request, based on expected response status codes.
/// </summary>
public sealed class RetryPolicy
{
public RetryPolicy(int initialBackoff, int numAttempts, HashSet<HttpStatusCode> continueOn, HashSet<HttpStatusCode> retryOn, HashSet<HttpStatusCode> abortOn = null)
{
InitialBackoff = initialBackoff;
MaxAttempts = numAttempts;
ContinueOn = continueOn;
RetryOn = retryOn;
AbortOn = abortOn;
}
/// <summary>
/// Initial wait following the first failed/throttled call.
/// The interval is doubled for each subsequent attempt.
/// </summary>
public int InitialBackoff { get; set; }
/// <summary>
/// Maximum number of attempts to try, inclusive of the first one.
/// </summary>
public int MaxAttempts { get; set; }
/// <summary>
/// Status codes considered successful (i.e. the request will not be re-attempted.)
/// </summary>
public HashSet<HttpStatusCode> ContinueOn { get; set; }
/// <summary>
/// Status codes on which to retry, after a wait.
/// </summary>
public HashSet<HttpStatusCode> RetryOn { get; set; }
/// <summary>
/// Status codes on which to abort the execution of the retry block.
/// </summary>
public HashSet<HttpStatusCode> AbortOn { get; set; }
}
}