Skip to content

Commit

Permalink
Update k8s and v1
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeButters committed Jun 20, 2024
1 parent 6830d14 commit 3794be9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<KubernetesScriptStatusResponseV1> _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
{
Expand All @@ -111,14 +105,16 @@ void OnErrorAction(Exception ex)
}
}

scriptStatusResponse = await rpcCallExecutor.Execute(
var scriptStatusResponse = await rpcCallExecutor.Execute(
retriesEnabled: clientOptions.RpcRetrySettings.RetriesEnabled,
RpcCall.Create<IKubernetesScriptServiceV1>(nameof(IKubernetesScriptServiceV1.StartScript)),
StartScriptAction,
OnErrorAction,
logger,
clientOperationMetricsBuilder,
scriptExecutionCancellationToken).ConfigureAwait(false);

return (MapToScriptStatus(scriptStatusResponse), MapToNextStatus(scriptStatusResponse));
}
catch (Exception ex) when (scriptExecutionCancellationToken.IsCancellationRequested)
{
Expand All @@ -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<ProcessOutput>(),
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<ProcessOutput>());
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ScriptStatusResponse> _StartScript(ExecuteScriptCommand executeScriptCommand, CancellationToken scriptExecutionCancellationToken)
public async Task<(ScriptStatus, ITicketForNextStatus)> StartScript(ExecuteScriptCommand executeScriptCommand, CancellationToken scriptExecutionCancellationToken)
{
var command = Map(executeScriptCommand);
var scriptTicket = await rpcCallExecutor.ExecuteWithNoRetries(
Expand All @@ -86,7 +81,7 @@ private async Task<ScriptStatusResponse> _StartScript(ExecuteScriptCommand execu
clientOperationMetricsBuilder,
scriptExecutionCancellationToken).ConfigureAwait(false);

return new ScriptStatusResponse(scriptTicket, ProcessState.Pending, 0, new List<ProcessOutput>(), 0);
return Map(new ScriptStatusResponse(scriptTicket, ProcessState.Pending, 0, new List<ProcessOutput>(), 0));
}

public async Task<(ScriptStatus, ITicketForNextStatus)> GetStatus(ITicketForNextStatus lastStatusResponse, CancellationToken scriptExecutionCancellationToken)
Expand Down

0 comments on commit 3794be9

Please sign in to comment.