Skip to content

Commit

Permalink
fix(tasks): don't throw errors on cancellation
Browse files Browse the repository at this point in the history
  • Loading branch information
SonicGD committed Dec 5, 2024
1 parent c3d5e80 commit 1f664ba
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/Sitko.Core.Tasks/Execution/BaseTaskExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,14 @@ private async Task<TTask> ExecuteTaskAsync(Guid id, CancellationToken cancellati
await scopedRepository.UpdateAsync(scopedTask, CancellationToken.None);
}

await Task.Delay(TimeSpan.FromSeconds(5), activityTaskCts.Token);
try
{
await Task.Delay(TimeSpan.FromSeconds(5), activityTaskCts.Token);
}
catch (TaskCanceledException)
{
Logger.LogDebug("Activity task was cancelled");
}
}
}, activityTaskCts.Token);
try
Expand Down Expand Up @@ -156,7 +163,15 @@ private async Task<TTask> ExecuteTaskAsync(Guid id, CancellationToken cancellati
public void Dispose()
{
activityTaskCts.Cancel();
activityTask?.GetAwaiter().GetResult();
try
{
activityTask?.GetAwaiter().GetResult();
}
catch (Exception ex)
{
Logger.LogError(ex, "Error in activity task: {ErrorText}", ex.ToString());
}

GC.SuppressFinalize(this);
}
}
Expand Down

0 comments on commit 1f664ba

Please sign in to comment.