Implement configurable restart timeout

This commit is contained in:
Jordan Brown
2019-02-10 14:06:40 -05:00
parent 67b3abbb27
commit 37b9596db6
3 changed files with 22 additions and 3 deletions
@@ -23,6 +23,11 @@ namespace Tgstation.Server.Host.Configuration
/// </summary>
const int DefaultByondTopicTimeout = 5000;
/// <summary>
/// The default value for <see cref="RestartTimeout"/>
/// </summary>
const int DefaultRestartTimeout = 10000;
/// <summary>
/// Minimum length of database user passwords
/// </summary>
@@ -43,5 +48,10 @@ namespace Tgstation.Server.Host.Configuration
/// The timeout in milliseconds for sending and receiving topics to/from DreamDaemon. Note that a single topic exchange can take up to twice this value
/// </summary>
public int ByondTopicTimeout { get; set; } = DefaultByondTopicTimeout;
/// <summary>
/// The timeout milliseconds for restarting the server
/// </summary>
public int RestartTimeout { get; set; } = DefaultRestartTimeout;
}
}
+10 -2
View File
@@ -1,12 +1,14 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Tgstation.Server.Host.Configuration;
using Tgstation.Server.Host.Core;
using Tgstation.Server.Host.IO;
@@ -43,6 +45,11 @@ namespace Tgstation.Server.Host
/// </summary>
ILogger<Server> logger;
/// <summary>
/// The <see cref="GeneralConfiguration"/> for the <see cref="Server"/>
/// </summary>
GeneralConfiguration generalConfiguration;
/// <summary>
/// The <see cref="cancellationTokenSource"/> for the <see cref="Server"/>
/// </summary>
@@ -115,6 +122,8 @@ namespace Tgstation.Server.Host
try
{
logger = webHost.Services.GetRequiredService<ILogger<Server>>();
var generalConfigurationOptions = webHost.Services.GetRequiredService<IOptions<GeneralConfiguration>>();
generalConfiguration = generalConfigurationOptions.Value;
await webHost.RunAsync(cancellationTokenSource.Token).ConfigureAwait(false);
}
catch (OperationCanceledException)
@@ -264,8 +273,7 @@ namespace Tgstation.Server.Host
var cancellationToken = cts.Token;
var eventsTask = Task.WhenAll(restartHandlers.Select(x => x.HandleRestart(newVersion, cancellationToken)).ToList());
// YA GOT 10 SECONDS
var expiryTask = Task.Delay(TimeSpan.FromSeconds(10));
var expiryTask = Task.Delay(TimeSpan.FromMilliseconds(generalConfiguration.RestartTimeout));
await Task.WhenAny(eventsTask, expiryTask).ConfigureAwait(false);
logger.LogTrace("Joining restart handlers...");
cts.Cancel();
+2 -1
View File
@@ -3,7 +3,8 @@
"MinimumPasswordLength": 15,
"GitHubAccessToken": null,
"SetupWizardMode": "AutoDetect",
"ByondTopicTimeout": 5000
"ByondTopicTimeout": 5000,
"RestartTimeout": 10000
},
"FileLogging": {
"Directory": null, //use the default path