diff --git a/source/Octopus.Tentacle.Client/Scripts/KubernetesScriptServiceV1Orchestrator.cs b/source/Octopus.Tentacle.Client/Scripts/KubernetesScriptServiceV1Orchestrator.cs index 027093e06..ff1f8cfb3 100644 --- a/source/Octopus.Tentacle.Client/Scripts/KubernetesScriptServiceV1Orchestrator.cs +++ b/source/Octopus.Tentacle.Client/Scripts/KubernetesScriptServiceV1Orchestrator.cs @@ -79,18 +79,12 @@ private ScriptStatus MapToScriptStatus(KubernetesScriptStatusResponseV1 scriptSt private ITicketForNextStatus MapToNextStatus(KubernetesScriptStatusResponseV1 scriptStatusResponse) { - return new DefaultTicketForNextStatus(scriptStatusResponse.ScriptTicket, scriptStatusResponse.NextLogSequence, ScriptServiceVersion.ScriptServiceVersion1); + return new DefaultTicketForNextStatus(scriptStatusResponse.ScriptTicket, scriptStatusResponse.NextLogSequence, ScriptServiceVersion.KubernetesScriptServiceVersion1); } - 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); - KubernetesScriptStatusResponseV1 scriptStatusResponse; var startScriptCallsConnectedCount = 0; try { @@ -111,7 +105,7 @@ void OnErrorAction(Exception ex) } } - scriptStatusResponse = await rpcCallExecutor.Execute( + var scriptStatusResponse = await rpcCallExecutor.Execute( retriesEnabled: clientOptions.RpcRetrySettings.RetriesEnabled, RpcCall.Create(nameof(IKubernetesScriptServiceV1.StartScript)), StartScriptAction, @@ -119,6 +113,8 @@ void OnErrorAction(Exception ex) logger, clientOperationMetricsBuilder, scriptExecutionCancellationToken).ConfigureAwait(false); + + return (MapToScriptStatus(scriptStatusResponse), MapToNextStatus(scriptStatusResponse)); } catch (Exception ex) when (scriptExecutionCancellationToken.IsCancellationRequested) { @@ -132,36 +128,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 KubernetesScriptStatusResponseV1( - 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.KubernetesScriptServiceVersion1); + 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) diff --git a/source/Octopus.Tentacle.Client/Scripts/ScriptServiceV1Orchestrator.cs b/source/Octopus.Tentacle.Client/Scripts/ScriptServiceV1Orchestrator.cs index 58799c694..551247882 100644 --- a/source/Octopus.Tentacle.Client/Scripts/ScriptServiceV1Orchestrator.cs +++ b/source/Octopus.Tentacle.Client/Scripts/ScriptServiceV1Orchestrator.cs @@ -66,12 +66,7 @@ private ITicketForNextStatus MapToNextStatus(ScriptStatusResponse scriptStatusRe 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); var scriptTicket = await rpcCallExecutor.ExecuteWithNoRetries( @@ -86,7 +81,7 @@ private async Task _StartScript(ExecuteScriptCommand execu clientOperationMetricsBuilder, scriptExecutionCancellationToken).ConfigureAwait(false); - return new ScriptStatusResponse(scriptTicket, ProcessState.Pending, 0, new List(), 0); + return Map(new ScriptStatusResponse(scriptTicket, ProcessState.Pending, 0, new List(), 0)); } public async Task<(ScriptStatus, ITicketForNextStatus)> GetStatus(ITicketForNextStatus lastStatusResponse, CancellationToken scriptExecutionCancellationToken)