Skip to content

Commit 26fb3cc

Browse files
authored
Catch and Log when V1 complete script throws (#1166)
* Catch and Log when V1 complete script throws * .
1 parent 50630ad commit 26fb3cc

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

source/Octopus.Tentacle.Client/Scripts/ScriptServiceV1Executor.cs

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Linq;
44
using System.Threading;
55
using System.Threading.Tasks;
6+
using Halibut;
67
using Halibut.ServiceModel;
78
using Octopus.Tentacle.Client.EventDriven;
89
using Octopus.Tentacle.Client.Execution;
@@ -165,21 +166,31 @@ public async Task<ScriptOperationExecutionResult> CancelScript(CommandContext co
165166

166167
public async Task<ScriptStatus?> CompleteScript(CommandContext lastStatusResponse, CancellationToken scriptExecutionCancellationToken)
167168
{
168-
using var activity = TentacleClient.ActivitySource.StartActivity($"{nameof(ScriptServiceV1Executor)}.{nameof(CompleteScript)}");
169-
var response = await rpcCallExecutor.ExecuteWithNoRetries(
170-
RpcCall.Create<IScriptService>(nameof(IScriptService.CompleteScript)),
171-
async ct =>
172-
{
173-
var request = new CompleteScriptCommand(lastStatusResponse.ScriptTicket, lastStatusResponse.NextLogSequence);
174-
var result = await clientScriptServiceV1.CompleteScriptAsync(request, new HalibutProxyRequestOptions(ct));
175-
176-
return result;
177-
},
178-
logger,
179-
clientOperationMetricsBuilder,
180-
CancellationToken.None).ConfigureAwait(false);
169+
try
170+
{
171+
using var activity = TentacleClient.ActivitySource.StartActivity($"{nameof(ScriptServiceV1Executor)}.{nameof(CompleteScript)}");
172+
var response = await rpcCallExecutor.ExecuteWithNoRetries(
173+
RpcCall.Create<IScriptService>(nameof(IScriptService.CompleteScript)),
174+
async ct =>
175+
{
176+
var request = new CompleteScriptCommand(lastStatusResponse.ScriptTicket, lastStatusResponse.NextLogSequence);
177+
var result = await clientScriptServiceV1.CompleteScriptAsync(request, new HalibutProxyRequestOptions(ct));
178+
179+
return result;
180+
},
181+
logger,
182+
clientOperationMetricsBuilder,
183+
CancellationToken.None).ConfigureAwait(false);
184+
185+
return MapToScriptStatus(response);
186+
}
187+
catch (Exception ex) when (ex is HalibutClientException or OperationCanceledException)
188+
{
189+
logger.Warn("Failed to cleanup the script working directory on Tentacle");
190+
logger.Verbose(ex);
191+
}
181192

182-
return MapToScriptStatus(response);
193+
return null;
183194
}
184195
}
185196
}

source/Octopus.Tentacle.Tests.Integration/ClientScriptExecutionScriptServiceV1IsNotRetried.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,7 @@ public async Task WhenANetworkFailureOccurs_DuringCompleteScript_WithATentacleTh
235235
var startScriptCommand = new TestExecuteShellScriptCommandBuilder().SetScriptBody(new ScriptBuilder().Print("hello")).Build();
236236

237237
var logs = new List<ProcessOutput>();
238-
var executeScriptTask = clientTentacle.TentacleClient.ExecuteScript(startScriptCommand, logs, CancellationToken);
239-
240-
var expectedException = new ExceptionContractAssertionBuilder(FailureScenario.ConnectionFaulted, tentacleConfigurationTestCase.TentacleType, clientTentacle).Build();
241-
242-
await AssertionExtensions.Should(async () => await executeScriptTask).ThrowExceptionContractAsync(expectedException);
238+
await clientTentacle.TentacleClient.ExecuteScript(startScriptCommand, logs, CancellationToken);
243239

244240
// We Can not verify what will be in the logs because of race conditions in tentacle.
245241
// The last complete script which we fail might come back with the logs.

0 commit comments

Comments
 (0)