Skip to content

Commit

Permalink
Move cancellation token to last param
Browse files Browse the repository at this point in the history
  • Loading branch information
APErebus committed Dec 15, 2023
1 parent d8d0273 commit e1fbeed
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public KubernetesJobScriptExecutor(IKubernetesJobService jobService, IKubernetes

public IRunningScript ExecuteOnBackgroundThread(StartScriptCommandV3Alpha command, IScriptWorkspace workspace, ScriptStateStore scriptStateStore, CancellationToken cancellationToken)
{
var runningScript = new RunningKubernetesJob(workspace, workspace.CreateLog(), command.ScriptTicket, command.TaskId, cancellationToken, log, scriptStateStore, jobService, podService, containerResolver, appInstanceSelector);
var runningScript = new RunningKubernetesJob(workspace, workspace.CreateLog(), command.ScriptTicket, command.TaskId, log, scriptStateStore, jobService, podService, containerResolver, appInstanceSelector, cancellationToken);

Task.Run(() => runningScript.Execute(), cancellationToken);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,18 @@ public class RunningKubernetesJob : IRunningScript
public ProcessState State { get; private set; }
public IScriptLog ScriptLog { get; }


public RunningKubernetesJob(
IScriptWorkspace workspace,
IScriptLog scriptLog,
ScriptTicket scriptTicket,
string taskId,
CancellationToken scriptCancellationToken,
ILog log,
IScriptStateStore stateStore,
IKubernetesJobService jobService,
IKubernetesPodService podService,
IKubernetesJobContainerResolver containerResolver,
IApplicationInstanceSelector appInstanceSelector)
IApplicationInstanceSelector appInstanceSelector,
CancellationToken scriptCancellationToken)
{
this.workspace = workspace;
this.scriptTicket = scriptTicket;
Expand Down Expand Up @@ -101,7 +100,7 @@ public async Task Execute()
}
catch (Exception e)
{
writer.WriteOutput(ProcessOutputSource.StdErr,$"Failed to cancel Kubernetes job {jobName}. {e}");
writer.WriteOutput(ProcessOutputSource.StdErr, $"Failed to cancel Kubernetes job {jobName}. {e}");
}
}, CancellationToken.None);
});
Expand All @@ -123,7 +122,7 @@ public async Task Execute()
RecordScriptHasStarted(writer);

//we now need to monitor the resulting pod status
exitCode = await MonitorJobAndLogs( writer);
exitCode = await MonitorJobAndLogs(writer);
}
}
catch (OperationCanceledException)
Expand Down Expand Up @@ -199,7 +198,7 @@ await jobService.Watch(scriptTicket, job =>
//if the job was killed by cancellation, then we need to change the exit code
if (scriptCancellationToken.IsCancellationRequested)
{
resultStatusCode = ScriptExitCodes.CanceledExitCode;
resultStatusCode = ScriptExitCodes.CanceledExitCode;
}

jobCompletionCancellationTokenSource.Cancel();
Expand Down

0 comments on commit e1fbeed

Please sign in to comment.