diff --git a/src/Tgstation.Server.Host/Components/Instance.cs b/src/Tgstation.Server.Host/Components/Instance.cs
index 95ca246c42..0e441edb15 100644
--- a/src/Tgstation.Server.Host/Components/Instance.cs
+++ b/src/Tgstation.Server.Host/Components/Instance.cs
@@ -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))
diff --git a/src/Tgstation.Server.Host/Jobs/JobHandler.cs b/src/Tgstation.Server.Host/Jobs/JobHandler.cs
index 19941fbefd..98cbe88651 100644
--- a/src/Tgstation.Server.Host/Jobs/JobHandler.cs
+++ b/src/Tgstation.Server.Host/Jobs/JobHandler.cs
@@ -11,6 +11,21 @@ namespace Tgstation.Server.Host.Jobs
///
sealed class JobHandler : IDisposable
{
+ ///
+ /// If the job has started.
+ ///
+ public bool Started => task != null;
+
+ ///
+ /// The progress of the job.
+ ///
+ public int? Progress { get; set; }
+
+ ///
+ /// The stage of the job.
+ ///
+ public string Stage { get; set; }
+
///
/// The for .
///
@@ -39,16 +54,6 @@ namespace Tgstation.Server.Host.Jobs
///
public void Dispose() => cancellationTokenSource.Dispose();
- ///
- /// The progress of the job.
- ///
- public int? Progress { get; set; }
-
- ///
- /// The stage of the job.
- ///
- public string Stage { get; set; }
-
///
/// Wait for to complete.
///
diff --git a/src/Tgstation.Server.Host/Jobs/JobService.cs b/src/Tgstation.Server.Host/Jobs/JobService.cs
index c0d01f2dcf..09350a4c4c 100644
--- a/src/Tgstation.Server.Host/Jobs/JobService.cs
+++ b/src/Tgstation.Server.Host/Jobs/JobService.cs
@@ -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);