Fix attempting to wait on a job after the JobService has stopped

This commit is contained in:
Dominion
2023-06-05 21:24:12 -04:00
parent 5824ccc1f5
commit bab9d81aa0
3 changed files with 27 additions and 14 deletions
@@ -514,11 +514,9 @@ namespace Tgstation.Server.Host.Components
await jobManager.RegisterOperation(
repositoryUpdateJob,
RepositoryAutoUpdateJob,
cancellationToken)
;
cancellationToken);
// DCT: First token will cancel the job, second is for cancelling the cancellation, unwanted
await jobManager.WaitForJobCompletion(repositoryUpdateJob, null, cancellationToken, default);
await jobManager.WaitForJobCompletion(repositoryUpdateJob, null, cancellationToken, cancellationToken);
Job compileProcessJob;
using (var repo = await RepositoryManager.LoadRepository(cancellationToken))
+15 -10
View File
@@ -11,6 +11,21 @@ namespace Tgstation.Server.Host.Jobs
/// </summary>
sealed class JobHandler : IDisposable
{
/// <summary>
/// If the job has started.
/// </summary>
public bool Started => task != null;
/// <summary>
/// The progress of the job.
/// </summary>
public int? Progress { get; set; }
/// <summary>
/// The stage of the job.
/// </summary>
public string Stage { get; set; }
/// <summary>
/// The <see cref="CancellationTokenSource"/> for <see cref="task"/>.
/// </summary>
@@ -39,16 +54,6 @@ namespace Tgstation.Server.Host.Jobs
/// <inheritdoc />
public void Dispose() => cancellationTokenSource.Dispose();
/// <summary>
/// The progress of the job.
/// </summary>
public int? Progress { get; set; }
/// <summary>
/// The stage of the job.
/// </summary>
public string Stage { get; set; }
/// <summary>
/// Wait for <see cref="task"/> to complete.
/// </summary>
@@ -256,13 +256,23 @@ namespace Tgstation.Server.Host.Jobs
{
if (job == null)
throw new ArgumentNullException(nameof(job));
if (!cancellationToken.CanBeCanceled)
throw new ArgumentException("A cancellable CancellationToken should be provided!", nameof(cancellationToken));
JobHandler handler;
bool noMoreJobsShouldStart;
lock (synchronizationLock)
{
if (!jobs.TryGetValue(job.Id.Value, out handler))
return;
noMoreJobsShouldStart = this.noMoreJobsShouldStart;
}
if (noMoreJobsShouldStart && !handler.Started)
await Extensions.TaskExtensions.InfiniteTask().WithToken(cancellationToken);
Task cancelTask = null;
using (jobCancellationToken.Register(() => cancelTask = CancelJob(job, canceller, true, cancellationToken)))
await handler.Wait(cancellationToken);