diff --git a/code/DeltaKustoIntegration/Kusto/KustoManagementGateway.cs b/code/DeltaKustoIntegration/Kusto/KustoManagementGateway.cs index a11ef812..3fd6c87e 100644 --- a/code/DeltaKustoIntegration/Kusto/KustoManagementGateway.cs +++ b/code/DeltaKustoIntegration/Kusto/KustoManagementGateway.cs @@ -21,9 +21,22 @@ namespace DeltaKustoIntegration.Kusto /// internal class KustoManagementGateway : IKustoManagementGateway { - private static readonly AsyncRetryPolicy _retryPolicy = Policy - .Handle(ex => !ex.IsPermanent) - .WaitAndRetryAsync(3, attempt => TimeSpan.FromSeconds(attempt)); + private static readonly ResiliencePipeline _resiliencePipeline = new ResiliencePipelineBuilder() + .AddRetry(new RetryStrategyOptions + { + ShouldHandle = new PredicateBuilder().Handle(ex => !ex.IsPermanent), + MaxRetryAttempts = 3, + BackoffType = DelayBackoffType.Linear, + Delay = TimeSpan.FromSeconds(1) + }) + .AddRetry(new RetryStrategyOptions + { + ShouldHandle = new PredicateBuilder().Handle(ex => ex.FailureCode==401), + MaxRetryAttempts = 1, + BackoffType = DelayBackoffType.Linear, + Delay = TimeSpan.FromSeconds(1) + }) + .Build(); private readonly Uri _clusterUri; private readonly string _database; @@ -139,7 +152,7 @@ private async Task ExecuteCommandAsync( { try { - return await _retryPolicy.ExecuteAsync(async () => + return await _resiliencePipeline.ExecuteAsync(async (ct) => { var reader = await _commandProvider.ExecuteControlCommandAsync( _database, @@ -147,7 +160,7 @@ private async Task ExecuteCommandAsync( _requestProperties); return reader; - }); + }, ct); } catch (Exception ex) {