Class PollyRetryOperation
- Namespace
- WorkflowForge.Extensions.Resilience.Polly
- Assembly
- WorkflowForge.Extensions.Resilience.Polly.dll
A Polly-powered retry operation that can wrap any workflow operation with advanced resilience policies. Provides enterprise-grade fault tolerance and can override base resilience functionality.
public sealed class PollyRetryOperation : WorkflowOperationBase, IWorkflowOperation, IDisposable
- Inheritance
-
PollyRetryOperation
- Implements
- Inherited Members
- Extension Methods
Properties
Name
Gets the name of this operation for identification and logging purposes.
public override string Name { get; }
Property Value
Methods
Dispose(bool)
Releases managed resources. Override in derived classes to dispose of owned resources.
protected override void Dispose(bool disposing)
Parameters
ForgeAsyncCore(object?, IWorkflowFoundry, CancellationToken)
Core operation logic. Implement this method with your operation's business logic. This is called between OnBeforeExecuteAsync and OnAfterExecuteAsync.
protected override Task<object?> ForgeAsyncCore(object? inputData, IWorkflowFoundry foundry, CancellationToken cancellationToken = default)
Parameters
inputDataobjectThe input data for the operation.
foundryIWorkflowFoundryThe workflow foundry providing context and services.
cancellationTokenCancellationTokenThe cancellation token.
Returns
RestoreAsync(object?, IWorkflowFoundry, CancellationToken)
Restores (compensates) the operation's effects to undo its changes. Used for rollback scenarios when subsequent operations fail.
public override Task RestoreAsync(object? outputData, IWorkflowFoundry foundry, CancellationToken cancellationToken = default)
Parameters
outputDataobjectThe data that was produced by this operation during ForgeAsync.
foundryIWorkflowFoundryThe workflow foundry providing execution context and shared services.
cancellationTokenCancellationTokenThe cancellation token for cooperative cancellation.
Returns
- Task
A task representing the asynchronous restoration.
Remarks
The base implementation is a no-op. Override this method in your operation to provide compensation/rollback logic. Operations that don't override this are safely skipped during compensation.
Exceptions
- ArgumentNullException
Thrown when foundry is null.
- ObjectDisposedException
Thrown when the operation has been disposed.
WithCircuitBreakerPolicy(IWorkflowOperation, int, TimeSpan?, IWorkflowForgeLogger?, string?)
Creates a Polly retry operation with circuit breaker policy.
public static PollyRetryOperation WithCircuitBreakerPolicy(IWorkflowOperation innerOperation, int failureThreshold = 5, TimeSpan? durationOfBreak = null, IWorkflowForgeLogger? logger = null, string? name = null)
Parameters
innerOperationIWorkflowOperationThe operation to wrap.
failureThresholdintNumber of failures before opening the circuit.
durationOfBreakTimeSpan?Duration to keep the circuit open.
loggerIWorkflowForgeLoggerOptional logger for operation events.
namestringOptional custom name.
Returns
- PollyRetryOperation
A new Polly retry operation with circuit breaker.
WithComprehensivePolicy(IWorkflowOperation, PollyMiddlewareOptions, IWorkflowForgeLogger?, string?)
Creates a comprehensive Polly retry operation combining retry, circuit breaker, and timeout.
public static PollyRetryOperation WithComprehensivePolicy(IWorkflowOperation innerOperation, PollyMiddlewareOptions settings, IWorkflowForgeLogger? logger = null, string? name = null)
Parameters
innerOperationIWorkflowOperationThe operation to wrap.
settingsPollyMiddlewareOptionsPolly settings configuration.
loggerIWorkflowForgeLoggerOptional logger for operation events.
namestringOptional custom name.
Returns
- PollyRetryOperation
A new comprehensive Polly retry operation.
WithRetryPolicy(IWorkflowOperation, int, TimeSpan?, TimeSpan?, IWorkflowForgeLogger?, string?)
Creates a Polly retry operation with exponential backoff retry policy.
public static PollyRetryOperation WithRetryPolicy(IWorkflowOperation innerOperation, int maxRetryAttempts = 3, TimeSpan? baseDelay = null, TimeSpan? maxDelay = null, IWorkflowForgeLogger? logger = null, string? name = null)
Parameters
innerOperationIWorkflowOperationThe operation to wrap.
maxRetryAttemptsintMaximum number of retry attempts.
baseDelayTimeSpan?Base delay for exponential backoff.
maxDelayTimeSpan?Maximum delay between retries.
loggerIWorkflowForgeLoggerOptional logger for operation events.
namestringOptional custom name.
Returns
- PollyRetryOperation
A new Polly retry operation.