Server Monitor Changes

- implemented the sequential server processing.
This commit is contained in:
Brett Hewitson 2022-05-20 01:08:00 +10:00
parent 1d6907a471
commit 27c762cefb
6 changed files with 274 additions and 82 deletions

View file

@ -68,6 +68,8 @@ namespace ServerManagerTool.Windows
}
}
private const int DELAY_PROCESSCOMPLETE = 5000; // 5 seconds
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private static readonly List<ServerMonitorWindow> Windows = new List<ServerMonitorWindow>();
@ -1176,7 +1178,7 @@ namespace ServerManagerTool.Windows
case ServerStatus.Uninstalled:
case ServerStatus.Unknown:
case ServerStatus.Updating:
AddErrorBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileBadStatus"), server.Profile.ServerName, server.Runtime.StatusString));
AddErrorBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileBadStatus"), server.Profile.ProfileName, server.Runtime.StatusString));
continue;
}
@ -1209,24 +1211,45 @@ namespace ServerManagerTool.Windows
}
};
var task = Task.Run(() =>
var task = new Task(() =>
{
AddMessageBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_BackupRequested"), profile.ServerName));
app.PerformProfileBackup(profile, token);
Task.Delay(5000).Wait();
Task.Delay(DELAY_PROCESSCOMPLETE).Wait();
AddMessageBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_CommandComplete"), profile.ServerName));
_currentProfileCommands.Remove(profile.ProfileId);
}, token);
tasks.Add(task);
AddMessageBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_BackupRequested"), profile.ServerName));
}
try
{
await Task.WhenAll(tasks);
if (processServersSequentially)
{
foreach (var task in tasks)
{
token.ThrowIfCancellationRequested();
task.Start();
await task;
await Task.Delay(sequentialProcessDelay * 1000, token);
}
}
else
{
foreach (var task in tasks)
{
token.ThrowIfCancellationRequested();
task.Start();
}
await Task.WhenAll(tasks);
}
}
catch (OperationCanceledException)
{
@ -1278,19 +1301,19 @@ namespace ServerManagerTool.Windows
case ServerStatus.Stopping:
case ServerStatus.Uninstalled:
case ServerStatus.Unknown:
AddErrorBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileBadStatus"), server.Profile.ServerName, server.Runtime.StatusString));
AddErrorBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileBadStatus"), server.Profile.ProfileName, server.Runtime.StatusString));
continue;
case ServerStatus.Running:
if (!restart)
{
AddErrorBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileBadStatus"), server.Profile.ServerName, server.Runtime.StatusString));
AddErrorBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileBadStatus"), server.Profile.ProfileName, server.Runtime.StatusString));
continue;
}
break;
case ServerStatus.Updating:
AddErrorBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileUpdating"), server.Profile.ServerName));
AddErrorBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileUpdating"), server.Profile.ProfileName));
continue;
}
@ -1325,27 +1348,48 @@ namespace ServerManagerTool.Windows
}
};
var task = Task.Run(() =>
var task = new Task(() =>
{
if (restart)
AddMessageBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_RestartRequested"), profile.ServerName));
else
AddMessageBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_StartRequested"), profile.ServerName));
app.PerformProfileShutdown(profile, true, ServerUpdateType.None, false, false, token);
Task.Delay(5000).Wait();
Task.Delay(DELAY_PROCESSCOMPLETE).Wait();
AddMessageBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_CommandComplete"), profile.ServerName));
_currentProfileCommands.Remove(profile.ProfileId);
}, token);
tasks.Add(task);
if (restart)
AddMessageBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_RestartRequested"), profile.ServerName));
else
AddMessageBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_StartRequested"), profile.ServerName));
}
try
{
await Task.WhenAll(tasks);
if (processServersSequentially)
{
foreach (var task in tasks)
{
token.ThrowIfCancellationRequested();
task.Start();
await task;
await Task.Delay(sequentialProcessDelay * 1000, token);
}
}
else
{
foreach (var task in tasks)
{
token.ThrowIfCancellationRequested();
task.Start();
}
await Task.WhenAll(tasks);
}
}
catch (OperationCanceledException)
{
@ -1395,16 +1439,23 @@ namespace ServerManagerTool.Windows
switch (server.Runtime.Status)
{
case ServerStatus.Initializing:
case ServerStatus.Stopping:
case ServerStatus.Stopped:
case ServerStatus.Uninstalled:
case ServerStatus.Unknown:
AddErrorBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileBadStatus"), server.Profile.ServerName, server.Runtime.StatusString));
AddErrorBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileBadStatus"), server.Profile.ProfileName, server.Runtime.StatusString));
continue;
case ServerStatus.Initializing:
if (shutdown)
{
AddErrorBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileBadStatus"), server.Profile.ProfileName, server.Runtime.StatusString));
continue;
}
break;
case ServerStatus.Updating:
AddErrorBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileUpdating"), server.Profile.ServerName));
AddErrorBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileUpdating"), server.Profile.ProfileName));
continue;
}
@ -1442,27 +1493,48 @@ namespace ServerManagerTool.Windows
if (!shutdown)
app.ShutdownInterval = 0;
var task = Task.Run(() =>
var task = new Task(() =>
{
if (shutdown)
AddMessageBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_ShutdownRequested"), profile.ServerName));
else
AddMessageBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_StopRequested"), profile.ServerName));
app.PerformProfileShutdown(profile, false, ServerUpdateType.None, false, false, token);
Task.Delay(5000).Wait();
Task.Delay(DELAY_PROCESSCOMPLETE).Wait();
AddMessageBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_CommandComplete"), profile.ServerName));
_currentProfileCommands.Remove(profile.ProfileId);
}, token);
tasks.Add(task);
if (shutdown)
AddMessageBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_ShutdownRequested"), profile.ServerName));
else
AddMessageBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_StopRequested"), profile.ServerName));
}
try
{
await Task.WhenAll(tasks);
if (processServersSequentially)
{
foreach (var task in tasks)
{
token.ThrowIfCancellationRequested();
task.Start();
await task;
await Task.Delay(sequentialProcessDelay * 1000, token);
}
}
else
{
foreach (var task in tasks)
{
token.ThrowIfCancellationRequested();
task.Start();
}
await Task.WhenAll(tasks);
}
}
catch (OperationCanceledException)
{
@ -1519,11 +1591,11 @@ namespace ServerManagerTool.Windows
case ServerStatus.Initializing:
case ServerStatus.Stopping:
case ServerStatus.Unknown:
AddErrorBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileBadStatus"), server.Profile.ServerName, server.Runtime.StatusString));
AddErrorBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileBadStatus"), server.Profile.ProfileName, server.Runtime.StatusString));
continue;
case ServerStatus.Updating:
AddErrorBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileUpdating"), server.Profile.ServerName));
AddErrorBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileUpdating"), server.Profile.ProfileName));
continue;
}
@ -1558,24 +1630,45 @@ namespace ServerManagerTool.Windows
}
};
var task = Task.Run(() =>
var task = new Task(() =>
{
AddMessageBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_UpdateRequested"), profile.ServerName));
app.PerformProfileShutdown(profile, profile.RestartAfterShutdown1, updateModsOnly ? ServerUpdateType.Mods : ServerUpdateType.ServerAndMods, false, false, token);
Task.Delay(5000).Wait();
Task.Delay(DELAY_PROCESSCOMPLETE).Wait();
AddMessageBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_CommandComplete"), profile.ServerName));
_currentProfileCommands.Remove(profile.ProfileId);
}, token);
tasks.Add(task);
AddMessageBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_UpdateRequested"), profile.ServerName));
}
try
{
await Task.WhenAll(tasks);
if (processServersSequentially)
{
foreach (var task in tasks)
{
token.ThrowIfCancellationRequested();
task.Start();
await task;
await Task.Delay(sequentialProcessDelay * 1000, token);
}
}
else
{
foreach (var task in tasks)
{
token.ThrowIfCancellationRequested();
task.Start();
}
await Task.WhenAll(tasks);
}
}
catch (OperationCanceledException)
{