Class RetrySyntax
- Namespace
- Polly
- Assembly
- Polly.dll
Fluent API for defining a Retry Policy.
public static class RetrySyntax
- Inheritance
-
RetrySyntax
- Inherited Members
Methods
Retry(PolicyBuilder)
Builds a Policy that will retry once.
public static RetryPolicy Retry(this PolicyBuilder policyBuilder)
Parameters
policyBuilder
PolicyBuilderThe policy builder.
Returns
- RetryPolicy
The policy instance.
Retry(PolicyBuilder, Action<Exception, int, Context>)
Builds a Policy that will retry once
calling onRetry
on retry with the raised exception, retry count and context data.
public static RetryPolicy Retry(this PolicyBuilder policyBuilder, Action<Exception, int, Context> onRetry)
Parameters
policyBuilder
PolicyBuilderThe policy builder.
onRetry
Action<Exception, int, Context>The action to call on each retry.
Returns
- RetryPolicy
The policy instance.
Exceptions
- ArgumentNullException
onRetry
Retry(PolicyBuilder, Action<Exception, int>)
Builds a Policy that will retry once
calling onRetry
on retry with the raised exception and retry count.
public static RetryPolicy Retry(this PolicyBuilder policyBuilder, Action<Exception, int> onRetry)
Parameters
policyBuilder
PolicyBuilderThe policy builder.
onRetry
Action<Exception, int>The action to call on each retry.
Returns
- RetryPolicy
The policy instance.
Exceptions
- ArgumentNullException
onRetry
Retry(PolicyBuilder, int)
Builds a Policy that will retry retryCount
times.
public static RetryPolicy Retry(this PolicyBuilder policyBuilder, int retryCount)
Parameters
policyBuilder
PolicyBuilderThe policy builder.
retryCount
intThe retry count.
Returns
- RetryPolicy
The policy instance.
Retry(PolicyBuilder, int, Action<Exception, int, Context>)
Builds a Policy that will retry retryCount
times
calling onRetry
on each retry with the raised exception, retry count and context data.
public static RetryPolicy Retry(this PolicyBuilder policyBuilder, int retryCount, Action<Exception, int, Context> onRetry)
Parameters
policyBuilder
PolicyBuilderThe policy builder.
retryCount
intThe retry count.
onRetry
Action<Exception, int, Context>The action to call on each retry.
Returns
- RetryPolicy
The policy instance.
Exceptions
- ArgumentOutOfRangeException
retryCount;Value must be greater than or equal to zero.
- ArgumentNullException
onRetry
Retry(PolicyBuilder, int, Action<Exception, int>)
Builds a Policy that will retry retryCount
times
calling onRetry
on each retry with the raised exception and retry count.
public static RetryPolicy Retry(this PolicyBuilder policyBuilder, int retryCount, Action<Exception, int> onRetry)
Parameters
policyBuilder
PolicyBuilderThe policy builder.
retryCount
intThe retry count.
onRetry
Action<Exception, int>The action to call on each retry.
Returns
- RetryPolicy
The policy instance.
Exceptions
- ArgumentOutOfRangeException
retryCount;Value must be greater than or equal to zero.
- ArgumentNullException
onRetry
RetryForever(PolicyBuilder)
Builds a Policy that will retry indefinitely until the action succeeds.
public static RetryPolicy RetryForever(this PolicyBuilder policyBuilder)
Parameters
policyBuilder
PolicyBuilderThe policy builder.
Returns
- RetryPolicy
The policy instance.
RetryForever(PolicyBuilder, Action<Exception, Context>)
Builds a Policy that will retry indefinitely
calling onRetry
on each retry with the raised exception and context data.
public static RetryPolicy RetryForever(this PolicyBuilder policyBuilder, Action<Exception, Context> onRetry)
Parameters
policyBuilder
PolicyBuilderThe policy builder.
onRetry
Action<Exception, Context>The action to call on each retry.
Returns
- RetryPolicy
The policy instance.
Exceptions
- ArgumentNullException
onRetry
RetryForever(PolicyBuilder, Action<Exception>)
Builds a Policy that will retry indefinitely
calling onRetry
on each retry with the raised exception.
public static RetryPolicy RetryForever(this PolicyBuilder policyBuilder, Action<Exception> onRetry)
Parameters
policyBuilder
PolicyBuilderThe policy builder.
onRetry
Action<Exception>The action to call on each retry.
Returns
- RetryPolicy
The policy instance.
Exceptions
- ArgumentNullException
onRetry
WaitAndRetry(PolicyBuilder, IEnumerable<TimeSpan>)
Builds a Policy that will wait and retry as many times as there are provided sleepDurations
On each retry, the duration to wait is the current sleepDurations
item.
public static RetryPolicy WaitAndRetry(this PolicyBuilder policyBuilder, IEnumerable<TimeSpan> sleepDurations)
Parameters
policyBuilder
PolicyBuilderThe policy builder.
sleepDurations
IEnumerable<TimeSpan>The sleep durations to wait for on each retry.
Returns
- RetryPolicy
The policy instance.
WaitAndRetry(PolicyBuilder, IEnumerable<TimeSpan>, Action<Exception, TimeSpan, Context>)
Builds a Policy that will wait and retry as many times as there are provided sleepDurations
calling onRetry
on each retry with the raised exception, current sleep duration and context data.
On each retry, the duration to wait is the current sleepDurations
item.
public static RetryPolicy WaitAndRetry(this PolicyBuilder policyBuilder, IEnumerable<TimeSpan> sleepDurations, Action<Exception, TimeSpan, Context> onRetry)
Parameters
policyBuilder
PolicyBuilderThe policy builder.
sleepDurations
IEnumerable<TimeSpan>The sleep durations to wait for on each retry.
onRetry
Action<Exception, TimeSpan, Context>The action to call on each retry.
Returns
- RetryPolicy
The policy instance.
Exceptions
- ArgumentNullException
sleepDurations or onRetry
WaitAndRetry(PolicyBuilder, IEnumerable<TimeSpan>, Action<Exception, TimeSpan, int, Context>)
Builds a Policy that will wait and retry as many times as there are provided sleepDurations
calling onRetry
on each retry with the raised exception, current sleep duration, retry count and context data.
On each retry, the duration to wait is the current sleepDurations
item.
public static RetryPolicy WaitAndRetry(this PolicyBuilder policyBuilder, IEnumerable<TimeSpan> sleepDurations, Action<Exception, TimeSpan, int, Context> onRetry)
Parameters
policyBuilder
PolicyBuilderThe policy builder.
sleepDurations
IEnumerable<TimeSpan>The sleep durations to wait for on each retry.
onRetry
Action<Exception, TimeSpan, int, Context>The action to call on each retry.
Returns
- RetryPolicy
The policy instance.
Exceptions
- ArgumentNullException
sleepDurations or onRetry
WaitAndRetry(PolicyBuilder, IEnumerable<TimeSpan>, Action<Exception, TimeSpan>)
Builds a Policy that will wait and retry as many times as there are provided sleepDurations
calling onRetry
on each retry with the raised exception and the current sleep duration.
On each retry, the duration to wait is the current sleepDurations
item.
public static RetryPolicy WaitAndRetry(this PolicyBuilder policyBuilder, IEnumerable<TimeSpan> sleepDurations, Action<Exception, TimeSpan> onRetry)
Parameters
policyBuilder
PolicyBuilderThe policy builder.
sleepDurations
IEnumerable<TimeSpan>The sleep durations to wait for on each retry.
onRetry
Action<Exception, TimeSpan>The action to call on each retry.
Returns
- RetryPolicy
The policy instance.
Exceptions
- ArgumentNullException
sleepDurations or onRetry
WaitAndRetry(PolicyBuilder, int, Func<int, Context, TimeSpan>)
Builds a Policy that will wait and retry retryCount
times.
On each retry, the duration to wait is calculated by calling sleepDurationProvider
with
the current retry attempt allowing an exponentially increasing wait time (exponential backoff).
public static RetryPolicy WaitAndRetry(this PolicyBuilder policyBuilder, int retryCount, Func<int, Context, TimeSpan> sleepDurationProvider)
Parameters
policyBuilder
PolicyBuilderThe policy builder.
retryCount
intThe retry count.
sleepDurationProvider
Func<int, Context, TimeSpan>The function that provides the duration to wait for for a particular retry attempt.
Returns
- RetryPolicy
The policy instance.
WaitAndRetry(PolicyBuilder, int, Func<int, Context, TimeSpan>, Action<Exception, TimeSpan, Context>)
Builds a Policy that will wait and retry retryCount
times
calling onRetry
on each retry with the raised exception, current sleep duration and context data.
On each retry, the duration to wait is calculated by calling sleepDurationProvider
with
the current retry attempt allowing an exponentially increasing wait time (exponential backoff).
public static RetryPolicy WaitAndRetry(this PolicyBuilder policyBuilder, int retryCount, Func<int, Context, TimeSpan> sleepDurationProvider, Action<Exception, TimeSpan, Context> onRetry)
Parameters
policyBuilder
PolicyBuilderThe policy builder.
retryCount
intThe retry count.
sleepDurationProvider
Func<int, Context, TimeSpan>The function that provides the duration to wait for for a particular retry attempt.
onRetry
Action<Exception, TimeSpan, Context>The action to call on each retry.
Returns
- RetryPolicy
The policy instance.
Exceptions
- ArgumentOutOfRangeException
retryCount;Value must be greater than or equal to zero.
- ArgumentNullException
sleepDurationProvider or onRetry
WaitAndRetry(PolicyBuilder, int, Func<int, Context, TimeSpan>, Action<Exception, TimeSpan, int, Context>)
Builds a Policy that will wait and retry retryCount
times
calling onRetry
on each retry with the raised exception, current sleep duration, retry count, and context data.
On each retry, the duration to wait is calculated by calling sleepDurationProvider
with
the current retry attempt allowing an exponentially increasing wait time (exponential backoff).
public static RetryPolicy WaitAndRetry(this PolicyBuilder policyBuilder, int retryCount, Func<int, Context, TimeSpan> sleepDurationProvider, Action<Exception, TimeSpan, int, Context> onRetry)
Parameters
policyBuilder
PolicyBuilderThe policy builder.
retryCount
intThe retry count.
sleepDurationProvider
Func<int, Context, TimeSpan>The function that provides the duration to wait for for a particular retry attempt.
onRetry
Action<Exception, TimeSpan, int, Context>The action to call on each retry.
Returns
- RetryPolicy
The policy instance.
Exceptions
- ArgumentOutOfRangeException
retryCount;Value must be greater than or equal to zero.
- ArgumentNullException
timeSpanProvider or onRetry
WaitAndRetry(PolicyBuilder, int, Func<int, TimeSpan>)
Builds a Policy that will wait and retry retryCount
times.
On each retry, the duration to wait is calculated by calling sleepDurationProvider
with
the current retry attempt allowing an exponentially increasing wait time (exponential backoff).
public static RetryPolicy WaitAndRetry(this PolicyBuilder policyBuilder, int retryCount, Func<int, TimeSpan> sleepDurationProvider)
Parameters
policyBuilder
PolicyBuilderThe policy builder.
retryCount
intThe retry count.
sleepDurationProvider
Func<int, TimeSpan>The function that provides the duration to wait for for a particular retry attempt.
Returns
- RetryPolicy
The policy instance.
WaitAndRetry(PolicyBuilder, int, Func<int, TimeSpan>, Action<Exception, TimeSpan, Context>)
Builds a Policy that will wait and retry retryCount
times
calling onRetry
on each retry with the raised exception, current sleep duration and context data.
On each retry, the duration to wait is calculated by calling sleepDurationProvider
with
the current retry attempt allowing an exponentially increasing wait time (exponential backoff).
public static RetryPolicy WaitAndRetry(this PolicyBuilder policyBuilder, int retryCount, Func<int, TimeSpan> sleepDurationProvider, Action<Exception, TimeSpan, Context> onRetry)
Parameters
policyBuilder
PolicyBuilderThe policy builder.
retryCount
intThe retry count.
sleepDurationProvider
Func<int, TimeSpan>The function that provides the duration to wait for for a particular retry attempt.
onRetry
Action<Exception, TimeSpan, Context>The action to call on each retry.
Returns
- RetryPolicy
The policy instance.
Exceptions
- ArgumentOutOfRangeException
retryCount;Value must be greater than or equal to zero.
- ArgumentNullException
sleepDurationProvider or onRetry
WaitAndRetry(PolicyBuilder, int, Func<int, TimeSpan>, Action<Exception, TimeSpan, int, Context>)
Builds a Policy that will wait and retry retryCount
times
calling onRetry
on each retry with the raised exception, current sleep duration, retry count, and context data.
On each retry, the duration to wait is calculated by calling sleepDurationProvider
with
the current retry attempt allowing an exponentially increasing wait time (exponential backoff).
public static RetryPolicy WaitAndRetry(this PolicyBuilder policyBuilder, int retryCount, Func<int, TimeSpan> sleepDurationProvider, Action<Exception, TimeSpan, int, Context> onRetry)
Parameters
policyBuilder
PolicyBuilderThe policy builder.
retryCount
intThe retry count.
sleepDurationProvider
Func<int, TimeSpan>The function that provides the duration to wait for for a particular retry attempt.
onRetry
Action<Exception, TimeSpan, int, Context>The action to call on each retry.
Returns
- RetryPolicy
The policy instance.
Exceptions
- ArgumentOutOfRangeException
retryCount;Value must be greater than or equal to zero.
- ArgumentNullException
timeSpanProvider or onRetry
WaitAndRetry(PolicyBuilder, int, Func<int, TimeSpan>, Action<Exception, TimeSpan>)
Builds a Policy that will wait and retry retryCount
times
calling onRetry
on each retry with the raised exception and the current sleep duration.
On each retry, the duration to wait is calculated by calling sleepDurationProvider
with
the current retry attempt allowing an exponentially increasing wait time (exponential backoff).
public static RetryPolicy WaitAndRetry(this PolicyBuilder policyBuilder, int retryCount, Func<int, TimeSpan> sleepDurationProvider, Action<Exception, TimeSpan> onRetry)
Parameters
policyBuilder
PolicyBuilderThe policy builder.
retryCount
intThe retry count.
sleepDurationProvider
Func<int, TimeSpan>The function that provides the duration to wait for for a particular retry attempt.
onRetry
Action<Exception, TimeSpan>The action to call on each retry.
Returns
- RetryPolicy
The policy instance.
Exceptions
- ArgumentOutOfRangeException
retryCount;Value must be greater than or equal to zero.
- ArgumentNullException
sleepDurationProvider or onRetry
WaitAndRetryForever(PolicyBuilder, Func<int, Context, TimeSpan>)
Builds a Policy that will wait and retry indefinitely until the action succeeds.
public static RetryPolicy WaitAndRetryForever(this PolicyBuilder policyBuilder, Func<int, Context, TimeSpan> sleepDurationProvider)
Parameters
policyBuilder
PolicyBuilderThe policy builder.
sleepDurationProvider
Func<int, Context, TimeSpan>The function that provides the duration to wait for for a particular retry attempt.
Returns
- RetryPolicy
The policy instance.
Exceptions
- ArgumentNullException
sleepDurationProvider
WaitAndRetryForever(PolicyBuilder, Func<int, Context, TimeSpan>, Action<Exception, TimeSpan, Context>)
Builds a Policy that will wait and retry indefinitely until the action succeeds,
calling onRetry
on each retry with the raised exception and
execution context.
public static RetryPolicy WaitAndRetryForever(this PolicyBuilder policyBuilder, Func<int, Context, TimeSpan> sleepDurationProvider, Action<Exception, TimeSpan, Context> onRetry)
Parameters
policyBuilder
PolicyBuilderThe policy builder.
sleepDurationProvider
Func<int, Context, TimeSpan>A function providing the duration to wait before retrying.
onRetry
Action<Exception, TimeSpan, Context>The action to call on each retry.
Returns
- RetryPolicy
The policy instance.
Exceptions
- ArgumentNullException
sleepDurationProvider
- ArgumentNullException
onRetry
WaitAndRetryForever(PolicyBuilder, Func<int, TimeSpan>)
Builds a Policy that will wait and retry indefinitely until the action succeeds.
public static RetryPolicy WaitAndRetryForever(this PolicyBuilder policyBuilder, Func<int, TimeSpan> sleepDurationProvider)
Parameters
policyBuilder
PolicyBuilderThe policy builder.
sleepDurationProvider
Func<int, TimeSpan>The function that provides the duration to wait for for a particular retry attempt.
Returns
- RetryPolicy
The policy instance.
Exceptions
- ArgumentNullException
sleepDurationProvider
WaitAndRetryForever(PolicyBuilder, Func<int, TimeSpan>, Action<Exception, TimeSpan>)
Builds a Policy that will wait and retry indefinitely until the action succeeds,
calling onRetry
on each retry with the raised exception.
public static RetryPolicy WaitAndRetryForever(this PolicyBuilder policyBuilder, Func<int, TimeSpan> sleepDurationProvider, Action<Exception, TimeSpan> onRetry)
Parameters
policyBuilder
PolicyBuilderThe policy builder.
sleepDurationProvider
Func<int, TimeSpan>A function providing the duration to wait before retrying.
onRetry
Action<Exception, TimeSpan>The action to call on each retry.
Returns
- RetryPolicy
The policy instance.
Exceptions
- ArgumentNullException
sleepDurationProvider
- ArgumentNullException
onRetry