diff --git a/src/Tgstation.Server.Host/Components/InstanceManager.cs b/src/Tgstation.Server.Host/Components/InstanceManager.cs index 323fa7568a..8c395077c3 100644 --- a/src/Tgstation.Server.Host/Components/InstanceManager.cs +++ b/src/Tgstation.Server.Host/Components/InstanceManager.cs @@ -41,6 +41,11 @@ namespace Tgstation.Server.Host.Components /// readonly IApplication application; + /// + /// The for the + /// + readonly IJobManager jobManager; + /// /// The for the /// @@ -62,13 +67,15 @@ namespace Tgstation.Server.Host.Components /// The value of /// The value of /// The value of + /// The value of /// The value of - public InstanceManager(IInstanceFactory instanceFactory, IIOManager ioManager, IDatabaseContextFactory databaseContextFactory, IApplication application, ILogger logger) + public InstanceManager(IInstanceFactory instanceFactory, IIOManager ioManager, IDatabaseContextFactory databaseContextFactory, IApplication application, IJobManager jobManager, ILogger logger) { this.instanceFactory = instanceFactory ?? throw new ArgumentNullException(nameof(instanceFactory)); this.ioManager = ioManager ?? throw new ArgumentNullException(nameof(ioManager)); this.databaseContextFactory = databaseContextFactory ?? throw new ArgumentNullException(nameof(databaseContextFactory)); this.application = application ?? throw new ArgumentNullException(nameof(application)); + this.jobManager = jobManager ?? throw new ArgumentNullException(nameof(jobManager)); this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); instances = new Dictionary(); @@ -161,6 +168,7 @@ namespace Tgstation.Server.Host.Components try { await databaseContext.Initialize(cancellationToken).ConfigureAwait(false); + await jobManager.StartAsync(cancellationToken).ConfigureAwait(false); var dbInstances = databaseContext.Instances.Where(x => x.Online.Value) .Include(x => x.RepositorySettings) .Include(x => x.ChatSettings) @@ -179,7 +187,11 @@ namespace Tgstation.Server.Host.Components }); /// - public Task StopAsync(CancellationToken cancellationToken) => Task.WhenAll(instances.Select(x => x.Value.StopAsync(cancellationToken))); + public async Task StopAsync(CancellationToken cancellationToken) + { + await Task.WhenAll(instances.Select(x => x.Value.StopAsync(cancellationToken))).ConfigureAwait(false); + await jobManager.StopAsync(cancellationToken).ConfigureAwait(false); + } /// public IInteropContext Register(string accessIdentifier, IInteropConsumer consumer) diff --git a/src/Tgstation.Server.Host/Core/Application.cs b/src/Tgstation.Server.Host/Core/Application.cs index 9674267ce9..78abc75d9c 100644 --- a/src/Tgstation.Server.Host/Core/Application.cs +++ b/src/Tgstation.Server.Host/Core/Application.cs @@ -215,11 +215,9 @@ namespace Tgstation.Server.Host.Core services.AddSingleton(); services.AddSingleton(x => x.GetRequiredService()); services.AddSingleton(x => x.GetRequiredService()); - - services.AddSingleton(); - services.AddSingleton(x => x.GetRequiredService()); - services.AddSingleton(x => x.GetRequiredService()); + services.AddSingleton(); + services.AddSingleton(ioManager); services.AddSingleton(); diff --git a/src/Tgstation.Server.Host/Core/IJobManager.cs b/src/Tgstation.Server.Host/Core/IJobManager.cs index 35f8d5c56e..beaa6010eb 100644 --- a/src/Tgstation.Server.Host/Core/IJobManager.cs +++ b/src/Tgstation.Server.Host/Core/IJobManager.cs @@ -1,4 +1,5 @@ using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; using System; using System.Threading; using System.Threading.Tasks; @@ -9,7 +10,7 @@ namespace Tgstation.Server.Host.Core /// /// Manages the runtime of s /// - public interface IJobManager + public interface IJobManager : IHostedService { /// /// Get the for a job diff --git a/src/Tgstation.Server.Host/Core/JobManager.cs b/src/Tgstation.Server.Host/Core/JobManager.cs index 88314172f0..a678d47efe 100644 --- a/src/Tgstation.Server.Host/Core/JobManager.cs +++ b/src/Tgstation.Server.Host/Core/JobManager.cs @@ -10,7 +10,7 @@ using Tgstation.Server.Host.Models; namespace Tgstation.Server.Host.Core { /// - sealed class JobManager : IHostedService, IJobManager, IDisposable + sealed class JobManager : IJobManager, IDisposable { /// /// The for the