Assembly: OptimaJet.Workflow.Core

Class RetryExtensions

OptimaJet.Workflow.Core.RetryExtensions

Provides extension methods for retrying asynchronous operations created by task factories.

public static class RetryExtensions

Methods

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
taskFactory
Func<Task<T>>
A delegate that creates a new Task<TResult> for each retry attempt.
retries
Int32
The number of additional attempts allowed after the first failed attempt.
delay
TimeSpan
The delay before the first retry attempt.
cancellationToken
CancellationToken
A token observed after each attempt and while waiting between attempts. It is not passed to taskFactory.
isRetryAllowed
Func<Exception, Boolean>
Optional predicate that decides whether a failed attempt can be retried. The predicate receives the AggregateException from the failed attempt.
progressiveDelay
Boolean
true to set the next delay to TimeSpan.FromTicks(long)(2 * delay.Ticks); false to reuse delay.

Returns

Type
Description
Task<T>
The value returned by a successful operation attempt.

Exceptions

Type
Description
AggregateException
Thrown when a fault is not eligible for another attempt or the retry limit is reached.
OperationCanceledException
Thrown 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
taskFactory
Func<Task<T>>
A delegate that creates a new Task<TResult> for each retry attempt.
retries
Int32
The number of additional attempts allowed after the first failed attempt.
delay
TimeSpan
The delay before the first retry attempt.
cancellationToken
CancellationToken
A 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
taskFactory
Func<Task>
A delegate that creates a new Task for each retry attempt.
retries
Int32
The number of additional attempts allowed after the first failed attempt.
delay
TimeSpan
The delay before the first retry attempt.
cancellationToken
CancellationToken
A token observed after each attempt and while waiting between attempts. It is not passed to taskFactory.
isRetryAllowed
Func<Exception, Boolean>
Optional predicate that decides whether a failed attempt can be retried. The predicate receives the AggregateException from the failed attempt.
progressiveDelay
Boolean
true to set the next delay from twice the TimeSpan.Milliseconds component of delay; false to reuse delay.

Returns

Type
Description
Task
A task that represents the full retry sequence.

Exceptions

Type
Description
AggregateException
Thrown when a fault is not eligible for another attempt or the retry limit is reached.
OperationCanceledException
Thrown 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
taskFactory
Func<Task>
A delegate that creates a new Task for each retry attempt.
retries
Int32
The number of additional attempts allowed after the first failed attempt.
delay
TimeSpan
The delay before the first retry attempt.
cancellationToken
CancellationToken
A token observed after each attempt and while waiting between attempts. It is not passed to taskFactory.

Returns

Type
Description
Task
A 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.