Class FixedIntervalStrategy
- Namespace
- WorkflowForge.Extensions.Resilience.Strategies
- Assembly
- WorkflowForge.Extensions.Resilience.dll
Implements a resilience strategy with fixed intervals between retry attempts.
public sealed class FixedIntervalStrategy : ResilienceStrategyBase, IWorkflowResilienceStrategy
- Inheritance
-
FixedIntervalStrategy
- Implements
- Inherited Members
Constructors
FixedIntervalStrategy(TimeSpan, int, Func<Exception, bool>?, IWorkflowForgeLogger?)
Initializes a new instance of the FixedIntervalStrategy class.
public FixedIntervalStrategy(TimeSpan interval, int maxAttempts, Func<Exception, bool>? retryPredicate = null, IWorkflowForgeLogger? logger = null)
Parameters
intervalTimeSpanThe fixed interval between retry attempts.
maxAttemptsintThe maximum number of attempts (including the initial attempt).
retryPredicateFunc<Exception, bool>Optional predicate to determine if an exception should be retried.
loggerIWorkflowForgeLoggerOptional logger for the strategy.
Methods
Default(int, IWorkflowForgeLogger?)
Creates a default fixed interval strategy with 1-second intervals.
public static FixedIntervalStrategy Default(int maxAttempts = 3, IWorkflowForgeLogger? logger = null)
Parameters
maxAttemptsintMaximum number of retry attempts.
loggerIWorkflowForgeLoggerOptional logger for strategy events.
Returns
- FixedIntervalStrategy
A new fixed interval strategy.
ExecuteAsync(Func<Task>, CancellationToken)
Executes an operation with resilience handling.
public override Task ExecuteAsync(Func<Task> operation, CancellationToken cancellationToken = default)
Parameters
operationFunc<Task>The operation to execute.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- Task
A task representing the asynchronous operation.
Fast(int, IWorkflowForgeLogger?)
Creates a fast fixed interval strategy with 100ms intervals.
public static FixedIntervalStrategy Fast(int maxAttempts = 5, IWorkflowForgeLogger? logger = null)
Parameters
maxAttemptsintMaximum number of retry attempts.
loggerIWorkflowForgeLoggerOptional logger for strategy events.
Returns
- FixedIntervalStrategy
A new fixed interval strategy.
GetRetryDelay(int, Exception?)
Gets the delay before the next retry attempt.
public override TimeSpan GetRetryDelay(int attemptNumber, Exception? exception)
Parameters
attemptNumberintThe current attempt number (1-based).
exceptionExceptionThe exception that occurred, if any.
Returns
- TimeSpan
The delay before the next retry attempt.
Slow(int, IWorkflowForgeLogger?)
Creates a slow fixed interval strategy with 5-second intervals.
public static FixedIntervalStrategy Slow(int maxAttempts = 2, IWorkflowForgeLogger? logger = null)
Parameters
maxAttemptsintMaximum number of retry attempts.
loggerIWorkflowForgeLoggerOptional logger for strategy events.
Returns
- FixedIntervalStrategy
A new fixed interval strategy.