/// <inheritdoc /> protected override async Task <IDmbProvider> PrepServerForLaunch(IDmbProvider dmbToUse, CancellationToken cancellationToken) { if (activeSwappable != null) { throw new InvalidOperationException("Expected activeSwappable to be null!"); } if (startupDmbProvider != null) { throw new InvalidOperationException("Expected startupDmbProvider to be null!"); } Logger.LogTrace("Prep for server launch. pendingSwappable is {0}available", pendingSwappable == null ? "not " : String.Empty); // Add another lock to the startup DMB because it'll be used throughout the lifetime of the watchdog startupDmbProvider = await DmbFactory.FromCompileJob(dmbToUse.CompileJob, cancellationToken).ConfigureAwait(false); activeSwappable = pendingSwappable ?? new WindowsSwappableDmbProvider(dmbToUse, ioManager, symlinkFactory); pendingSwappable = null; try { await activeSwappable.MakeActive(cancellationToken).ConfigureAwait(false); } catch { // We won't worry about disposing activeSwappable here as we can't dispose dmbToUse here. activeSwappable = null; throw; } return(activeSwappable); }
/// <inheritdoc /> protected override async Task HandleNewDmbAvailable(CancellationToken cancellationToken) { IDmbProvider compileJobProvider = DmbFactory.LockNextDmb(1); WindowsSwappableDmbProvider windowsProvider = null; try { windowsProvider = new WindowsSwappableDmbProvider(compileJobProvider, ioManager, symlinkFactory); Logger.LogDebug("Swapping to compile job {0}...", windowsProvider.CompileJob.Id); Server.Suspend(); await windowsProvider.MakeActive(cancellationToken).ConfigureAwait(false); Server.Resume(); } catch { IDmbProvider providerToDispose = windowsProvider ?? compileJobProvider; providerToDispose.Dispose(); throw; } pendingSwappable?.Dispose(); pendingSwappable = windowsProvider; }
/// <inheritdoc /> protected override async Task HandleNewDmbAvailable(CancellationToken cancellationToken) { IDmbProvider compileJobProvider = DmbFactory.LockNextDmb(1); if (compileJobProvider.CompileJob.ByondVersion != ActiveCompileJob.ByondVersion) { // have to do a graceful restart Logger.LogDebug( "Not swapping to new compile job {0} as it uses a different BYOND version ({1}) than what is currently active {2}. Queueing graceful restart instead...", compileJobProvider.CompileJob.Id, compileJobProvider.CompileJob.ByondVersion, ActiveCompileJob.ByondVersion); compileJobProvider.Dispose(); await base.HandleNewDmbAvailable(cancellationToken).ConfigureAwait(false); return; } WindowsSwappableDmbProvider windowsProvider = null; bool suspended = false; try { windowsProvider = new WindowsSwappableDmbProvider(compileJobProvider, ioManager, symlinkFactory); Logger.LogDebug("Swapping to compile job {0}...", windowsProvider.CompileJob.Id); try { Server.Suspend(); suspended = true; } catch (Exception ex) { Logger.LogWarning("Exception while suspending server: {0}", ex); } await windowsProvider.MakeActive(cancellationToken).ConfigureAwait(false); } catch (Exception ex) { Logger.LogError("Exception while swapping: {0}", ex); IDmbProvider providerToDispose = windowsProvider ?? compileJobProvider; providerToDispose.Dispose(); throw; } // Let this throw hard if it fails if (suspended) { Server.Resume(); } pendingSwappable?.Dispose(); pendingSwappable = windowsProvider; }
/// <inheritdoc /> protected override async Task <IDmbProvider> PrepServerForLaunch(IDmbProvider dmbToUse, CancellationToken cancellationToken) { Debug.Assert(activeSwappable == null, "Expected swappableDmbProvider to be null!"); Logger.LogTrace("Prep for server launch. pendingSwappable is {0}avaiable", pendingSwappable == null ? "not " : String.Empty); activeSwappable = pendingSwappable ?? new WindowsSwappableDmbProvider(dmbToUse, ioManager, symlinkFactory); pendingSwappable = null; try { await activeSwappable.MakeActive(cancellationToken).ConfigureAwait(false); } catch { // We won't worry about disposing activeSwappable here as we can't dispose dmbToUse here. activeSwappable = null; throw; } return(activeSwappable); }