Class RetryPolicy
Provides the base implementation of the retry mechanism for unreliable actions and transient conditions.
Inheritance
Namespace: Umbraco.Cms.Infrastructure.Persistence.FaultHandling
Assembly: cs.temp.dll.dll
Syntax
public class RetryPolicy
Constructors
RetryPolicy(ITransientErrorDetectionStrategy, Int32)
Initializes a new instance of the RetryPolicy class with the specified number of retry attempts and default fixed time interval between retries.
Declaration
public RetryPolicy(ITransientErrorDetectionStrategy errorDetectionStrategy, int retryCount)
Parameters
| Type | Name | Description |
|---|---|---|
| ITransientErrorDetectionStrategy | errorDetectionStrategy | The ITransientErrorDetectionStrategy that is responsible for detecting transient conditions. |
| System.Int32 | retryCount | The number of retry attempts. |
RetryPolicy(ITransientErrorDetectionStrategy, Int32, TimeSpan)
Initializes a new instance of the RetryPolicy class with the specified number of retry attempts and fixed time interval between retries.
Declaration
public RetryPolicy(ITransientErrorDetectionStrategy errorDetectionStrategy, int retryCount, TimeSpan retryInterval)
Parameters
| Type | Name | Description |
|---|---|---|
| ITransientErrorDetectionStrategy | errorDetectionStrategy | The ITransientErrorDetectionStrategy that is responsible for detecting transient conditions. |
| System.Int32 | retryCount | The number of retry attempts. |
| System.TimeSpan | retryInterval | The interval between retries. |
RetryPolicy(ITransientErrorDetectionStrategy, Int32, TimeSpan, TimeSpan)
Initializes a new instance of the RetryPolicy class with the specified number of retry attempts and parameters defining the progressive delay between retries.
Declaration
public RetryPolicy(ITransientErrorDetectionStrategy errorDetectionStrategy, int retryCount, TimeSpan initialInterval, TimeSpan increment)
Parameters
| Type | Name | Description |
|---|---|---|
| ITransientErrorDetectionStrategy | errorDetectionStrategy | The ITransientErrorDetectionStrategy that is responsible for detecting transient conditions. |
| System.Int32 | retryCount | The number of retry attempts. |
| System.TimeSpan | initialInterval | The initial interval that will apply for the first retry. |
| System.TimeSpan | increment | The incremental time value that will be used for calculating the progressive delay between retries. |
RetryPolicy(ITransientErrorDetectionStrategy, Int32, TimeSpan, TimeSpan, TimeSpan)
Initializes a new instance of the RetryPolicy class with the specified number of retry attempts and back-off parameters for calculating the exponential delay between retries.
Declaration
public RetryPolicy(ITransientErrorDetectionStrategy errorDetectionStrategy, int retryCount, TimeSpan minBackoff, TimeSpan maxBackoff, TimeSpan deltaBackoff)
Parameters
| Type | Name | Description |
|---|---|---|
| ITransientErrorDetectionStrategy | errorDetectionStrategy | The ITransientErrorDetectionStrategy that is responsible for detecting transient conditions. |
| System.Int32 | retryCount | The number of retry attempts. |
| System.TimeSpan | minBackoff | The minimum back-off time. |
| System.TimeSpan | maxBackoff | The maximum back-off time. |
| System.TimeSpan | deltaBackoff | The time value that will be used for calculating a random delta in the exponential delay between retries. |
RetryPolicy(ITransientErrorDetectionStrategy, RetryStrategy)
Initializes a new instance of the RetryPolicy class with the specified number of retry attempts and parameters defining the progressive delay between retries.
Declaration
public RetryPolicy(ITransientErrorDetectionStrategy errorDetectionStrategy, RetryStrategy retryStrategy)
Parameters
| Type | Name | Description |
|---|---|---|
| ITransientErrorDetectionStrategy | errorDetectionStrategy | The ITransientErrorDetectionStrategy that is responsible for detecting transient conditions. |
| RetryStrategy | retryStrategy | The retry strategy to use for this retry policy. |
Fields
DefaultExponential
Returns a default policy that implements a random exponential retry interval configured with the default
Declaration
public static readonly RetryPolicy DefaultExponential
Field Value
| Type | Description |
|---|---|
| RetryPolicy |
DefaultFixed
Returns a default policy that implements a fixed retry interval configured with the default
Declaration
public static readonly RetryPolicy DefaultFixed
Field Value
| Type | Description |
|---|---|
| RetryPolicy |
DefaultProgressive
Returns a default policy that implements a progressive retry interval configured with the default
Declaration
public static readonly RetryPolicy DefaultProgressive
Field Value
| Type | Description |
|---|---|
| RetryPolicy |
NoRetry
Returns a default policy that does no retries, it just invokes action exactly once.
Declaration
public static readonly RetryPolicy NoRetry
Field Value
| Type | Description |
|---|---|
| RetryPolicy |
Properties
ErrorDetectionStrategy
Gets the instance of the error detection strategy.
Declaration
public ITransientErrorDetectionStrategy ErrorDetectionStrategy { get; }
Property Value
| Type | Description |
|---|---|
| ITransientErrorDetectionStrategy |
RetryStrategy
Gets the retry strategy.
Declaration
public RetryStrategy RetryStrategy { get; }
Property Value
| Type | Description |
|---|---|
| RetryStrategy |
Methods
ExecuteAction(Action)
Repetitively executes the specified action while it satisfies the current retry policy.
Declaration
public virtual void ExecuteAction(Action action)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Action | action | A delegate representing the executable action which doesn't return any results. |
ExecuteAction<TResult>(Func<TResult>)
Repetitively executes the specified action while it satisfies the current retry policy.
Declaration
public virtual TResult ExecuteAction<TResult>(Func<TResult> func)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Func<TResult> | func | A delegate representing the executable action which returns the result of type R. |
Returns
| Type | Description |
|---|---|
| TResult | The result from the action. |
Type Parameters
| Name | Description |
|---|---|
| TResult | The type of result expected from the executable action. |
OnRetrying(Int32, Exception, TimeSpan)
Notifies the subscribers whenever a retry condition is encountered.
Declaration
protected virtual void OnRetrying(int retryCount, Exception lastError, TimeSpan delay)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | retryCount | The current retry attempt count. |
| System.Exception | lastError | The exception which caused the retry conditions to occur. |
| System.TimeSpan | delay | The delay indicating how long the current thread will be suspended for before the next iteration will be invoked. |
Events
Retrying
An instance of a callback delegate that will be invoked whenever a retry condition is encountered.
Declaration
public event EventHandler<RetryingEventArgs> Retrying
Event Type
| Type | Description |
|---|---|
| System.EventHandler<RetryingEventArgs> |