Class RetryStrategyOptions<TResult>
Represents the options used to configure a retry strategy.
public class RetryStrategyOptions<TResult> : ResilienceStrategyOptions
Type Parameters
TResult
The type of result the retry strategy handles.
- Inheritance
-
RetryStrategyOptions<TResult>
- Derived
- Inherited Members
Constructors
RetryStrategyOptions()
Initializes a new instance of the RetryStrategyOptions<TResult> class.
public RetryStrategyOptions()
Properties
BackoffType
Gets or sets the type of the back-off.
public DelayBackoffType BackoffType { get; set; }
Property Value
- DelayBackoffType
The default value is Constant.
Remarks
This property is ignored when DelayGenerator is set.
Delay
Gets or sets the base delay between retries.
[Range(typeof(TimeSpan), "00:00:00", "1.00:00:00")]
public TimeSpan Delay { get; set; }
Property Value
- TimeSpan
The default value is 2 seconds.
Remarks
This value is used with the combination of BackoffType to generate the final delay for each individual retry attempt:
- Exponential: Represents the median delay to target before the first retry.
- Linear: Represents the initial delay, the following delays increasing linearly with this value.
- Constant Represents the constant delay between retries.
DelayGenerator
Gets or sets a generator that calculates the delay between retries.
public Func<RetryDelayGeneratorArguments<TResult>, ValueTask<TimeSpan?>>? DelayGenerator { get; set; }
Property Value
- Func<RetryDelayGeneratorArguments<TResult>, ValueTask<TimeSpan?>>
The default value is null.
Remarks
The generator can override the delay generated by the retry strategy. If the generator returns null, the delay generated by the retry strategy for that attempt will be used.
MaxDelay
Gets or sets the maximum delay between retries.
[Range(typeof(TimeSpan), "00:00:00", "1.00:00:00")]
public TimeSpan? MaxDelay { get; set; }
Property Value
Remarks
This property is used to cap the maximum delay between retries. It is useful when you want to limit the maximum delay after a certain number of retries when it could reach a unreasonably high values, especially if Exponential backoff is used. If not specified, the delay is not capped. This property is ignored for delays generated by DelayGenerator.
MaxRetryAttempts
Gets or sets the maximum number of retries to use, in addition to the original call.
[Range(1, 2147483647)]
public int MaxRetryAttempts { get; set; }
Property Value
- int
The default value is 3 retries.
Remarks
OnRetry
Gets or sets an event delegate that is raised when the retry happens.
public Func<OnRetryArguments<TResult>, ValueTask>? OnRetry { get; set; }
Property Value
- Func<OnRetryArguments<TResult>, ValueTask>
The default value is null.
Remarks
After this event, the result produced the by user-callback is discarded and disposed to prevent resource over-consumption. If you need to preserve the result for further processing, create the copy of the result or extract and store all necessary information from the result within the event.
ShouldHandle
Gets or sets a predicate that determines whether the retry should be executed for a given outcome.
[Required]
public Func<RetryPredicateArguments<TResult>, ValueTask<bool>> ShouldHandle { get; set; }
Property Value
- Func<RetryPredicateArguments<TResult>, ValueTask<bool>>
The default is a delegate that retries on any exception except OperationCanceledException. This property is required.
UseJitter
Gets or sets a value indicating whether jitter should be used when calculating the backoff delay between retries.
public bool UseJitter { get; set; }
Property Value
Remarks
See https://github.com/Polly-Contrib/Polly.Contrib.WaitAndRetry#new-jitter-recommendation for more details on how jitter can improve the resilience when the retries are correlated.