@@ -20,8 +20,12 @@ public class DistributedWorkflowClient(
2020 : IWorkflowClient
2121{
2222 private readonly LocalWorkflowClient _localWorkflowClient = ActivatorUtilities . CreateInstance < LocalWorkflowClient > ( serviceProvider , workflowInstanceId ) ;
23- private readonly Lazy < ResiliencePipeline > _retryPipeline = new ( ( ) => CreateRetryPipeline ( transientExceptionDetector , logger , workflowInstanceId ) ) ;
23+ private readonly ITransientExceptionDetector _transientExceptionDetector = transientExceptionDetector ;
24+ private readonly ILogger < DistributedWorkflowClient > _logger = logger ;
25+ private readonly Lazy < ResiliencePipeline > _retryPipeline = new ( CreateRetryPipelineForInstance ) ;
2426
27+ private ResiliencePipeline CreateRetryPipelineForInstance ( ) =>
28+ CreateRetryPipeline ( _transientExceptionDetector , _logger , WorkflowInstanceId ) ;
2529 public string WorkflowInstanceId => workflowInstanceId ;
2630
2731 public async Task < CreateWorkflowInstanceResponse > CreateInstanceAsync ( CreateWorkflowInstanceRequest request , CancellationToken cancellationToken = default )
@@ -133,17 +137,19 @@ private static ResiliencePipeline CreateRetryPipeline(
133137 ILogger < DistributedWorkflowClient > logger ,
134138 string workflowInstanceId )
135139 {
140+ const int maxRetryAttempts = 3 ;
141+
136142 return new ResiliencePipelineBuilder ( )
137143 . AddRetry ( new ( )
138144 {
139- MaxRetryAttempts = 3 ,
145+ MaxRetryAttempts = maxRetryAttempts ,
140146 Delay = TimeSpan . FromMilliseconds ( 500 ) ,
141147 BackoffType = DelayBackoffType . Exponential ,
142148 UseJitter = true ,
143- ShouldHandle = new PredicateBuilder ( ) . Handle < Exception > ( transientExceptionDetector . IsTransient ) ,
149+ ShouldHandle = new PredicateBuilder ( ) . Handle < Exception > ( ex => transientExceptionDetectionService . IsTransient ( ex ) ) ,
144150 OnRetry = args =>
145151 {
146- logger . LogWarning ( args . Outcome . Exception , "Transient error acquiring lock for workflow instance {WorkflowInstanceId}. Attempt {AttemptNumber} of {MaxAttempts}." , workflowInstanceId , args . AttemptNumber + 1 , 3 ) ;
152+ logger . LogWarning ( args . Outcome . Exception , "Transient error acquiring lock for workflow instance {WorkflowInstanceId}. Attempt {AttemptNumber} of {MaxAttempts}." , workflowInstanceId , args . AttemptNumber + 1 , maxRetryAttempts ) ;
147153 return ValueTask . CompletedTask ;
148154 }
149155 } )
0 commit comments