Merge pull request #657 from Cyberboss/CancelSoftActions

Cancel soft actions
This commit is contained in:
Jordan Brown
2018-09-16 11:54:27 -04:00
committed by GitHub
3 changed files with 23 additions and 5 deletions
@@ -76,5 +76,12 @@ namespace Tgstation.Server.Host.Components.Watchdog
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
/// <returns>A <see cref="Task"/> representing the running operation</returns>
Task Terminate(bool graceful, CancellationToken cancellationToken);
/// <summary>
/// Cancels pending graceful actions
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
/// <returns>A <see cref="Task"/> representing the running operation</returns>
Task ResetRebootState(CancellationToken cancellationToken);
}
}
@@ -764,6 +764,19 @@ namespace Tgstation.Server.Host.Components.Watchdog
return await LaunchNoLock(true, true, false, cancellationToken).ConfigureAwait(false);
}
/// <inheritdoc />
public async Task ResetRebootState(CancellationToken cancellationToken)
{
using (await SemaphoreSlimContext.Lock(semaphore, cancellationToken).ConfigureAwait(false))
{
if (!Running)
return;
var toClear = AlphaIsActive ? alphaServer : bravoServer;
if (toClear != null)
toClear.ResetRebootState();
}
}
/// <inheritdoc />
public async Task<WatchdogLaunchResult> Restart(bool graceful, CancellationToken cancellationToken)
{
@@ -784,12 +797,10 @@ namespace Tgstation.Server.Host.Components.Watchdog
return result;
}
var toReboot = AlphaIsActive ? alphaServer : bravoServer;
var other = AlphaIsActive ? bravoServer : alphaServer;
if (toReboot != null)
{
if (!await toReboot.SetRebootState(Components.Watchdog.RebootState.Restart, cancellationToken).ConfigureAwait(false))
logger.LogWarning("Unable to send reboot state change event!");
}
return null;
}
@@ -192,13 +192,13 @@ namespace Tgstation.Server.Host.Controllers
//run these in parallel because they are equally as important
await Task.WhenAll(DatabaseContext.Save(cancellationToken), wd.ChangeSettings(current, cancellationToken)).ConfigureAwait(false);
//soft shutdown/restart can't be cancelled because of how many things rely on them
//They can be alternated though
if (!oldSoftRestart.Value && current.SoftRestart.Value)
await wd.Restart(true, cancellationToken).ConfigureAwait(false);
else if (!oldSoftShutdown.Value && current.SoftShutdown.Value)
await wd.Terminate(true, cancellationToken).ConfigureAwait(false);
else if ((oldSoftRestart.Value && !current.SoftRestart.Value) || (oldSoftShutdown.Value && !current.SoftShutdown.Value))
await wd.ResetRebootState(cancellationToken).ConfigureAwait(false);
return await ReadImpl(current, cancellationToken).ConfigureAwait(false);
}