Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
samdanaei committed Jun 20, 2024
1 parent 3794be9 commit 2af0d74
Showing 1 changed file with 8 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,23 +84,17 @@ 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)
{
return (MapToScriptStatus(r), MapToNextStatus(r));
}

public async Task<(ScriptStatus, ITicketForNextStatus)> StartScript(ExecuteScriptCommand command, CancellationToken scriptExecutionCancellationToken)
{
return Map(await _StartScript(command, scriptExecutionCancellationToken));
}

private async Task<KubernetesScriptStatusResponseV1Alpha> _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
{
Expand All @@ -121,14 +115,16 @@ void OnErrorAction(Exception ex)
}
}

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

return (MapToScriptStatus(scriptStatusResponse), MapToNextStatus(scriptStatusResponse));
}
catch (Exception ex) when (scriptExecutionCancellationToken.IsCancellationRequested)
{
Expand All @@ -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<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.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)
Expand Down

0 comments on commit 2af0d74

Please sign in to comment.