Skip to content

Commit

Permalink
Mark run as Cancelled/Failed upon HostContext.RunnerShutdownToken sta…
Browse files Browse the repository at this point in the history
…te (#1792)

- github/c2c-actions-support#883
  • Loading branch information
Soe Tun authored Apr 4, 2022
1 parent d70f9f6 commit 7b677e0
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/Runner.Worker/StepsRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,10 @@ public async Task RunAsync(IExecutionContext jobContext)
// Test the condition again. The job was cancelled after the condition was originally evaluated.
jobCancelRegister = jobContext.CancellationToken.Register(() =>
{
// Mark job as cancelled
jobContext.Result = TaskResult.Canceled;
// Mark job as Cancelled or Failed depending on HostContext shutdown token's cancellation
jobContext.Result = HostContext.RunnerShutdownToken.IsCancellationRequested
? TaskResult.Failed
: TaskResult.Canceled;
jobContext.JobContext.Status = jobContext.Result?.ToActionResult();

step.ExecutionContext.Debug($"Re-evaluate condition on job cancellation for step: '{step.DisplayName}'.");
Expand Down Expand Up @@ -173,8 +175,10 @@ public async Task RunAsync(IExecutionContext jobContext)
{
if (jobContext.Result != TaskResult.Canceled)
{
// Mark job as cancelled
jobContext.Result = TaskResult.Canceled;
// Mark job as Cancelled or Failed depending on HostContext shutdown token's cancellation
jobContext.Result = HostContext.RunnerShutdownToken.IsCancellationRequested
? TaskResult.Failed
: TaskResult.Canceled;
jobContext.JobContext.Status = jobContext.Result?.ToActionResult();
}
}
Expand Down

0 comments on commit 7b677e0

Please sign in to comment.