Interface IRetryPolicy
Describes the behavior of an operation retry policy. These are used to retry operations that have failed due to transient errors.
Namespace: Neon.Retry
Assembly: Neon.Common.dll
Syntax
[ContractClass(typeof(IRetryPolicyContract))]
public interface IRetryPolicy
Properties
Timeout
Returns the optional policy timeout. When present, this specifies the maximum time the policy will continue retrying the operation.
Declaration
TimeSpan? Timeout { get; }
Property Value
Type | Description |
---|---|
TimeSpan? |
Methods
Clone(Func<Exception, bool>)
Returns a copy of the retry policy.
Declaration
IRetryPolicy Clone(Func<Exception, bool> transientDetector = null)
Parameters
Type | Name | Description |
---|---|---|
Func<Exception, bool> | transientDetector | Optionally specifies a replacement transient detector function that will be set in the cloned policy. |
Returns
Type | Description |
---|---|
IRetryPolicy | The policy copy. |
Invoke(Action, CancellationToken)
Retries a synchronous action that returns no result when it throws exceptions due to transient errors. The classification of what is a transient error, the interval between the retries as well as the number of times the operation are retried are determined by the policy implementation.
Declaration
void Invoke(Action action, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
Action | action | The synchronous action to be performed. |
CancellationToken | cancellationToken | Optionally specifies a cancellation token. |
InvokeAsync(Func<Task>, CancellationToken)
Retries an asynchronous action that returns no result when it throws exceptions due to transient errors. The classification of what is a transient error, the interval between the retries as well as the number of times the operation are retried are determined by the policy implementation.
Declaration
Task InvokeAsync(Func<Task> action, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
Func<Task> | action | The asynchronous action to be performed. |
CancellationToken | cancellationToken | Optionally specifies a cancellation token. |
Returns
Type | Description |
---|---|
Task |
InvokeAsync<TResult>(Func<Task<TResult>>, CancellationToken)
Retries an asynchronous action that returns TResult
when it throws exceptions
due to transient errors. he classification of what is a transient error, the interval
between the retries as well as the number of times the operation are retried are
determined by the policy implementation.
Declaration
Task<TResult> InvokeAsync<TResult>(Func<Task<TResult>> action, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
Func<Task<TResult>> | action | The asynchronous action to be performed. |
CancellationToken | cancellationToken | Optionally specifies a cancellation token. |
Returns
Type | Description |
---|---|
Task<TResult> | The action result. |
Type Parameters
Name | Description |
---|---|
TResult | The action result type. |
Invoke<TResult>(Func<TResult>, CancellationToken)
Retries a synchronous action that returns a result when it throws exceptions due to transient errors. The classification of what is a transient error, the interval between the retries as well as the number of times the operation are retried are determined by the policy implementation.
Declaration
TResult Invoke<TResult>(Func<TResult> action, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
Func<TResult> | action | The synchronous action to be performed. |
CancellationToken | cancellationToken | Optionally specifies a cancellation token. |
Returns
Type | Description |
---|---|
TResult | The action result. |
Type Parameters
Name | Description |
---|---|
TResult | The action result type. |
Events
OnTransient
Used to intercept and handle logging for transient exceptions detected by a retry policy. Handlers can set Handled in the argument passed to prevent subsequent handlers from being invoked and also prevent the transient exception from being logged.
When no handlers are added to this event, the default behavior is to log all transient failures.
Declaration
event Action<RetryTransientArgs> OnTransient
Event Type
Type | Description |
---|---|
Action<RetryTransientArgs> |