diff --git a/source/Octopus.Tentacle.Client/Scripts/KubernetesScriptServiceV1AlphaOrchestrator.cs b/source/Octopus.Tentacle.Client/Scripts/KubernetesScriptServiceV1AlphaOrchestrator.cs index 9a3c65c03..365a1f9b1 100644 --- a/source/Octopus.Tentacle.Client/Scripts/KubernetesScriptServiceV1AlphaOrchestrator.cs +++ b/source/Octopus.Tentacle.Client/Scripts/KubernetesScriptServiceV1AlphaOrchestrator.cs @@ -84,7 +84,7 @@ private ScriptStatus MapToScriptStatus(KubernetesScriptStatusResponseV1Alpha scr private ITicketForNextStatus MapToNextStatus(KubernetesScriptStatusResponseV1Alpha scriptStatusResponse) { - return new DefaultTicketForNextStatus(scriptStatusResponse.ScriptTicket, scriptStatusResponse.NextLogSequence, ScriptServiceVersion.ScriptServiceVersion1); + return new DefaultTicketForNextStatus(scriptStatusResponse.ScriptTicket, scriptStatusResponse.NextLogSequence, ScriptServiceVersion.KubernetesScriptServiceVersion1Alpha); } (ScriptStatus, ITicketForNextStatus) Map(KubernetesScriptStatusResponseV1Alpha r) @@ -92,15 +92,9 @@ private ITicketForNextStatus MapToNextStatus(KubernetesScriptStatusResponseV1Alp return (MapToScriptStatus(r), MapToNextStatus(r)); } - public async Task<(ScriptStatus, ITicketForNextStatus)> StartScript(ExecuteScriptCommand command, CancellationToken scriptExecutionCancellationToken) - { - return Map(await _StartScript(command, scriptExecutionCancellationToken)); - } - - private async Task _StartScript(ExecuteScriptCommand executeScriptCommand, CancellationToken scriptExecutionCancellationToken) + public async Task<(ScriptStatus, ITicketForNextStatus)> StartScript(ExecuteScriptCommand executeScriptCommand, CancellationToken scriptExecutionCancellationToken) { var command = Map(executeScriptCommand); - KubernetesScriptStatusResponseV1Alpha scriptStatusResponse; var startScriptCallsConnectedCount = 0; try { @@ -121,7 +115,7 @@ void OnErrorAction(Exception ex) } } - scriptStatusResponse = await rpcCallExecutor.Execute( + var scriptStatusResponse = await rpcCallExecutor.Execute( retriesEnabled: clientOptions.RpcRetrySettings.RetriesEnabled, RpcCall.Create(nameof(IKubernetesScriptServiceV1Alpha.StartScript)), StartScriptAction, @@ -129,6 +123,8 @@ void OnErrorAction(Exception ex) logger, clientOperationMetricsBuilder, scriptExecutionCancellationToken).ConfigureAwait(false); + + return (MapToScriptStatus(scriptStatusResponse), MapToNextStatus(scriptStatusResponse)); } catch (Exception ex) when (scriptExecutionCancellationToken.IsCancellationRequested) { @@ -142,36 +138,15 @@ void OnErrorAction(Exception ex) if (!startScriptCallIsConnecting || startScriptCallIsBeingRetried) { - // We have to assume the script started executing and call CancelScript and CompleteScript - // We don't have a response so we need to create one to continue the execution flow - scriptStatusResponse = new KubernetesScriptStatusResponseV1Alpha( - command.ScriptTicket, - ProcessState.Pending, - ScriptExitCodes.RunningExitCode, - new List(), - 0); - - try - { - new ShortCutTakenHere(); - //await ObserveUntilCompleteThenFinish(scriptStatusResponse, scriptExecutionCancellationToken).ConfigureAwait(false); - } - catch (Exception observerUntilCompleteException) - { - // Throw an error so the caller knows that execution of the script was cancelled - throw new OperationCanceledException("Script execution was cancelled", observerUntilCompleteException); - } - - // Throw an error so the caller knows that execution of the script was cancelled - throw new OperationCanceledException("Script execution was cancelled"); + var scriptStatus = new ScriptStatus(ProcessState.Pending, null, new List()); + var defaultTicketForNextStatus = new DefaultTicketForNextStatus(command.ScriptTicket, 0, ScriptServiceVersion.KubernetesScriptServiceVersion1Alpha); + return (scriptStatus, defaultTicketForNextStatus); } // If the StartScript call was not in-flight or being retries then we know the script has not started executing on Tentacle // So can exit without calling CancelScript or CompleteScript throw new OperationCanceledException("Script execution was cancelled", ex); } - - return scriptStatusResponse; } public async Task<(ScriptStatus, ITicketForNextStatus)> GetStatus(ITicketForNextStatus lastStatusResponse, CancellationToken scriptExecutionCancellationToken)