Skip to content

Commit

Permalink
Catch 401s that seem to come as throttle exception?
Browse files Browse the repository at this point in the history
  • Loading branch information
vplauzon committed Oct 25, 2023
1 parent d9619ab commit 9499150
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions code/DeltaKustoIntegration/Kusto/KustoManagementGateway.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,22 @@ namespace DeltaKustoIntegration.Kusto
/// </summary>
internal class KustoManagementGateway : IKustoManagementGateway
{
private static readonly AsyncRetryPolicy _retryPolicy = Policy
.Handle<KustoException>(ex => !ex.IsPermanent)
.WaitAndRetryAsync(3, attempt => TimeSpan.FromSeconds(attempt));
private static readonly ResiliencePipeline _resiliencePipeline = new ResiliencePipelineBuilder()
.AddRetry(new RetryStrategyOptions
{
ShouldHandle = new PredicateBuilder().Handle<KustoException>(ex => !ex.IsPermanent),
MaxRetryAttempts = 3,
BackoffType = DelayBackoffType.Linear,
Delay = TimeSpan.FromSeconds(1)
})
.AddRetry(new RetryStrategyOptions
{
ShouldHandle = new PredicateBuilder().Handle<KustoException>(ex => ex.FailureCode==401),
MaxRetryAttempts = 1,
BackoffType = DelayBackoffType.Linear,
Delay = TimeSpan.FromSeconds(1)
})
.Build();

private readonly Uri _clusterUri;
private readonly string _database;
Expand Down Expand Up @@ -139,15 +152,15 @@ private async Task<IDataReader> ExecuteCommandAsync(
{
try
{
return await _retryPolicy.ExecuteAsync(async () =>
return await _resiliencePipeline.ExecuteAsync(async (ct) =>
{
var reader = await _commandProvider.ExecuteControlCommandAsync(
_database,
commandScript,
_requestProperties);

return reader;
});
}, ct);
}
catch (Exception ex)
{
Expand Down

0 comments on commit 9499150

Please sign in to comment.