diff --git a/source/Octopus.Tentacle.Client.Tests/RpcCallRetryHandlerFixture.cs b/source/Octopus.Tentacle.Client.Tests/RpcCallRetryHandlerFixture.cs index f24559cf0..cec06c8ac 100644 --- a/source/Octopus.Tentacle.Client.Tests/RpcCallRetryHandlerFixture.cs +++ b/source/Octopus.Tentacle.Client.Tests/RpcCallRetryHandlerFixture.cs @@ -19,6 +19,36 @@ public class RpcCallRetryHandlerFixture { readonly TimeSpan retryBackoffBuffer = TimeSpan.FromSeconds(2); + //[Test] + public async Task? WhatDoesCancelledDo() + { + var expectedResult = Guid.NewGuid(); + + var handler = new RpcCallRetryHandler(TimeSpan.FromSeconds(60)); + + int count = 0; + + var result = await handler.ExecuteWithRetries( + async ct => + { + await Task.CompletedTask; + + count++; + if (count == 5) + { + return expectedResult; + } + + throw new Exception(); + }, + onRetryAction: null, + onTimeoutAction: null, + CancellationToken.None); + + result.Should().Be(expectedResult); + } + + [Test] public async Task ReturnsTheResultWhenNoRetries() { diff --git a/source/Octopus.Tentacle.Client/Execution/RpcCallExecutor.cs b/source/Octopus.Tentacle.Client/Execution/RpcCallExecutor.cs index 4851ebf9d..1d1af0040 100644 --- a/source/Octopus.Tentacle.Client/Execution/RpcCallExecutor.cs +++ b/source/Octopus.Tentacle.Client/Execution/RpcCallExecutor.cs @@ -74,6 +74,7 @@ public async Task ExecuteWithRetries( } catch (Exception e) { + logger.Warn(e, $"Error occured talking to tentacle, Is given CancellationToken cancelled? {cancellationToken.IsCancellationRequested} Is inner CT cancelled {ct.IsCancellationRequested}"); rpcCallMetricsBuilder.WithAttempt(TimedOperation.Failure(start, e, ct)); throw; } @@ -101,12 +102,14 @@ public async Task ExecuteWithRetries( logger.Info($"Could not communicate with Tentacle after {(int)elapsedDuration.TotalSeconds} seconds."); } }, + logger, cancellationToken); return response; } catch (Exception e) { + logger.Warn(e, "Some error occured talking to tentacle"); rpcCallMetricsBuilder.Failure(e, cancellationToken); throw; } diff --git a/source/Octopus.Tentacle.Client/Retries/RpcCallRetryHandler.cs b/source/Octopus.Tentacle.Client/Retries/RpcCallRetryHandler.cs index f180ec1b7..919960229 100644 --- a/source/Octopus.Tentacle.Client/Retries/RpcCallRetryHandler.cs +++ b/source/Octopus.Tentacle.Client/Retries/RpcCallRetryHandler.cs @@ -3,6 +3,7 @@ using System.Threading; using System.Threading.Tasks; using Octopus.Tentacle.Client.Scripts; +using Octopus.Tentacle.Contracts.Logging; using Polly; using Polly.Timeout; @@ -38,6 +39,16 @@ public async Task ExecuteWithRetries( OnRetryAction? onRetryAction, OnTimeoutAction? onTimeoutAction, CancellationToken cancellationToken) + { + return await ExecuteWithRetries(action, onRetryAction, onTimeoutAction, null, cancellationToken); + } + + public async Task ExecuteWithRetries( + Func> action, + OnRetryAction? onRetryAction, + OnTimeoutAction? onTimeoutAction, + ITentacleClientTaskLog? logger, + CancellationToken cancellationToken) { Exception? lastException = null; var started = new Stopwatch(); @@ -71,6 +82,10 @@ async Task OnRetryAction(Exception exception, TimeSpan sleepDuration, int retryC await onRetryAction.Invoke(exception, sleepDuration, retryCount, RetryTimeout, elapsedDuration, cancellationToken).ConfigureAwait(false); } } + else + { + logger?.Info("Decided not to retry"); + } } async Task OnTimeoutAction(Context? context, TimeSpan timeout, Task? task, Exception? exception)