Table of Contents

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

string

Methods

Dispose(bool)

Releases managed resources. Override in derived classes to dispose of owned resources.

protected override void Dispose(bool disposing)

Parameters

disposing bool

True if called from Dispose(), false if from a finalizer.

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

inputData object

The input data for the operation.

foundry IWorkflowFoundry

The workflow foundry providing context and services.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<object>

The output data from the operation.

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

outputData object

The data that was produced by this operation during ForgeAsync.

foundry IWorkflowFoundry

The workflow foundry providing execution context and shared services.

cancellationToken CancellationToken

The 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

innerOperation IWorkflowOperation

The operation to wrap.

failureThreshold int

Number of failures before opening the circuit.

durationOfBreak TimeSpan?

Duration to keep the circuit open.

logger IWorkflowForgeLogger

Optional logger for operation events.

name string

Optional 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

innerOperation IWorkflowOperation

The operation to wrap.

settings PollyMiddlewareOptions

Polly settings configuration.

logger IWorkflowForgeLogger

Optional logger for operation events.

name string

Optional 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

innerOperation IWorkflowOperation

The operation to wrap.

maxRetryAttempts int

Maximum number of retry attempts.

baseDelay TimeSpan?

Base delay for exponential backoff.

maxDelay TimeSpan?

Maximum delay between retries.

logger IWorkflowForgeLogger

Optional logger for operation events.

name string

Optional custom name.

Returns

PollyRetryOperation

A new Polly retry operation.