RetryPolicy

How a Graph retries a request that failed for a transient reason. Set it with Graph.WithRetryPolicy. Each kind of failure has its own RetryDelay; a null delay makes that kind of failure throw at once. The defaults and the status codes behind each kind are in the C# SDK guide.

RetryPolicy

class

RetryPolicy

public sealed class RetryPolicy

Controls how a Graph retries a request to the workspace that failed for a transient reason. Set it with WithRetryPolicy.

Remarks

Each kind of failure has its own delay. Setting a delay to null stops retrying that kind of failure: the request then fails on the first occurrence. Failures that are never transient - an invalid token (403), an unknown endpoint (404), a bad request (400) or an error the server reports in its response - are never retried.

Examples

 var graph = Graph.Connect("https://example.com", "my-token", "my-connector")
                  .WithRetryPolicy(new RetryPolicy
                  {
                      MaxRetries   = 5,
                      ServerError  = RetryDelay.Between(TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(15)),
                      NetworkError = RetryDelay.Fixed(TimeSpan.FromSeconds(10)),
                      Timeout      = null, // fail on the first timeout
                  });
 
Namespace
Curiosity.Library

Properties

NameDescription
MaxRetriesHow many times a request is retried after its first attempt before it fails. Defaults to 31. Zero disables retrying.
RateLimitedDelay after the server answered 429 (Too Many Requests). Defaults to a random delay between 1 and 6 seconds.
ServerErrorDelay after the server answered 500, 503, 504, 520 or 521, or reported a database deadlock. Defaults to a random delay between 60 and 120 seconds.
RetryIfUnavailableWhether a 503 (Service Unavailable) is retried, with the ServerError delay. Defaults to true. Set it to false to fail on the first 503 while still retrying the other server errors - for example when a workspace that is down or starting up should stop the run instead of holding it for minutes.
NetworkErrorDelay after the request could not reach the server (an HttpRequestException). Defaults to a random delay between 60 and 120 seconds.
TimeoutDelay after the request did not complete within the timeout set with WithTimeout. Defaults to a random delay between 60 and 360 seconds.
DefaultThe policy a Graph uses unless told otherwise.
NoneA policy that never retries: every request fails on its first transient error.
Property
RetryPolicy.MaxRetries
public int MaxRetries { get; set; }

How many times a request is retried after its first attempt before it fails. Defaults to 31. Zero disables retrying.

Property
RetryPolicy.RateLimited
public RetryDelay? RateLimited { get; set; }

Delay after the server answered 429 (Too Many Requests). Defaults to a random delay between 1 and 6 seconds.

Property
RetryPolicy.ServerError
public RetryDelay? ServerError { get; set; }

Delay after the server answered 500, 503, 504, 520 or 521, or reported a database deadlock. Defaults to a random delay between 60 and 120 seconds.

Property
RetryPolicy.RetryIfUnavailable
public bool RetryIfUnavailable { get; set; }

Whether a 503 (Service Unavailable) is retried, with the ServerError delay. Defaults to true. Set it to false to fail on the first 503 while still retrying the other server errors - for example when a workspace that is down or starting up should stop the run instead of holding it for minutes.

Property
RetryPolicy.NetworkError
public RetryDelay? NetworkError { get; set; }

Delay after the request could not reach the server (an HttpRequestException). Defaults to a random delay between 60 and 120 seconds.

Property
RetryPolicy.Timeout
public RetryDelay? Timeout { get; set; }

Delay after the request did not complete within the timeout set with WithTimeout. Defaults to a random delay between 60 and 360 seconds.

Property
RetryPolicy.Default
public static RetryPolicy Default {get; }

The policy a Graph uses unless told otherwise.

Property
RetryPolicy.None
public static RetryPolicy None {get; }

A policy that never retries: every request fails on its first transient error.

RetryDelay

struct

RetryDelay

public readonly struct RetryDelay

How long a RetryPolicy waits before retrying: a random delay between Min and Max. The randomness spreads out retries from many connectors that failed at the same moment.

Namespace
Curiosity.Library

Properties

NameDescription
MinThe shortest delay.
MaxThe longest delay.
Property
RetryDelay.Min
public TimeSpan Min { get; }

The shortest delay.

Property
RetryDelay.Max
public TimeSpan Max { get; }

The longest delay.

Methods

NameDescription
BetweenA random delay between min and max.
FixedAlways the same delay.
Method
RetryDelay.Between
public static RetryDelay Between(TimeSpan min, TimeSpan max)

A random delay between min and max.

Method
RetryDelay.Fixed
public static RetryDelay Fixed(TimeSpan delay)

Always the same delay.