Class RetryExtensions
OptimaJet.Workflow.Core.RetryExtensions
Provides extension methods for retrying asynchronous operations created by task factories.
Namespace: OptimaJet.Workflow.Core
public static class RetryExtensionsMethods
public static Task<T> RetryAsync<T>(this Func<Task<T>> taskFactory, int retries, TimeSpan delay, CancellationToken cancellationToken = default, Func<Exception, bool> isRetryAllowed = null, bool progressiveDelay = true) #Executes the asynchronous operation produced by
taskFactory and retries it when it faults.Parameters
Name
Type
Description
retriesInt32The number of additional attempts allowed after the first failed attempt.
delayTimeSpanThe delay before the first retry attempt.
cancellationTokenCancellationTokenA token observed after each attempt and while waiting between attempts. It is not passed to
taskFactory.isRetryAllowedFunc<Exception, Boolean>Optional predicate that decides whether a failed attempt can be retried. The predicate receives the AggregateException from the failed attempt.
progressiveDelayBooleanReturns
Type
Description
Task<T>The value returned by a successful operation attempt.
Exceptions
Type
Description
AggregateExceptionThrown when a fault is not eligible for another attempt or the retry limit is reached.
OperationCanceledExceptionThrown when
cancellationToken is canceled.public static Task<T> RetryWithDefaultRetryAllowedChecker<T>(this Func<Task<T>> taskFactory, int retries, TimeSpan delay, CancellationToken cancellationToken = default) #Executes the asynchronous operation produced by
taskFactory and retries it when it faults.Parameters
Name
Type
Description
retriesInt32The number of additional attempts allowed after the first failed attempt.
delayTimeSpanThe delay before the first retry attempt.
cancellationTokenCancellationTokenA token observed after each attempt and while waiting between attempts. It is not passed to
taskFactory.Returns
Type
Description
Task<T>A task that completes with the successful result of
taskFactory or fails when retries are exhausted.Remarks
Retries only when the exception itself or its Exception.InnerException chain contains a PersistenceProviderQueryException whose PersistenceProviderQueryException.IsRetryAllowed property is true.
public static Task RetryAsync(this Func<Task> taskFactory, int retries, TimeSpan delay, CancellationToken cancellationToken = default, Func<Exception, bool> isRetryAllowed = null, bool progressiveDelay = true) #Executes the asynchronous operation produced by
taskFactory and retries it when it faults.Parameters
Name
Type
Description
retriesInt32The number of additional attempts allowed after the first failed attempt.
delayTimeSpanThe delay before the first retry attempt.
cancellationTokenCancellationTokenA token observed after each attempt and while waiting between attempts. It is not passed to
taskFactory.isRetryAllowedFunc<Exception, Boolean>Optional predicate that decides whether a failed attempt can be retried. The predicate receives the AggregateException from the failed attempt.
progressiveDelayBooleantrue to set the next delay from twice the TimeSpan.Milliseconds component of
delay; false to reuse delay.Returns
Type
Description
TaskA task that represents the full retry sequence.
Exceptions
Type
Description
AggregateExceptionThrown when a fault is not eligible for another attempt or the retry limit is reached.
OperationCanceledExceptionThrown when
cancellationToken is canceled.public static Task RetryWithDefaultRetryAllowedChecker(this Func<Task> taskFactory, int retries, TimeSpan delay, CancellationToken cancellationToken = default) #Executes the asynchronous operation produced by
taskFactory and retries it when it faults.Parameters
Name
Type
Description
retriesInt32The number of additional attempts allowed after the first failed attempt.
delayTimeSpanThe delay before the first retry attempt.
cancellationTokenCancellationTokenA token observed after each attempt and while waiting between attempts. It is not passed to
taskFactory.Returns
Type
Description
TaskA task that represents the retry sequence.
Remarks
Retries only when the exception itself or its Exception.InnerException chain contains a PersistenceProviderQueryException whose PersistenceProviderQueryException.IsRetryAllowed property is true.