mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-25 22:17:51 +01:00
Fix attempting to wait on a job after the JobService has stopped
This commit is contained in:
@@ -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))
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user