mirror of
https://github.com/NoiTheCat/BirthdayBot.git
synced 2024-11-21 13:54:36 +00:00
Have program attempt to stop itself after 5 failures
This commit is contained in:
parent
57fc207bba
commit
5fcf69136d
2 changed files with 16 additions and 3 deletions
12
Program.cs
12
Program.cs
|
@ -33,12 +33,18 @@ namespace BirthdayBot
|
|||
Console.WriteLine($"{ts:u} [{source}] {item}");
|
||||
}
|
||||
|
||||
private static bool _dispose = false;
|
||||
private static void OnCancelKeyPressed(object sender, ConsoleCancelEventArgs e)
|
||||
{
|
||||
e.Cancel = true;
|
||||
if (_dispose) return;
|
||||
_dispose = true;
|
||||
ProgramStop();
|
||||
}
|
||||
|
||||
private static bool _stopping = false;
|
||||
public static void ProgramStop()
|
||||
{
|
||||
if (_stopping) return;
|
||||
_stopping = true;
|
||||
|
||||
var dispose = Task.Run(_bot.Dispose);
|
||||
if (!dispose.Wait(90000))
|
||||
{
|
||||
|
|
|
@ -25,6 +25,11 @@ namespace BirthdayBot
|
|||
/// </summary>
|
||||
private const int WatchdogInterval = 90;
|
||||
|
||||
/// <summary>
|
||||
/// Number of shards allowed to be destroyed before forcing the program to close.
|
||||
/// </summary>
|
||||
private const int MaxDestroyedShards = 5;
|
||||
|
||||
/// <summary>
|
||||
/// A dictionary with shard IDs as its keys and shard instances as its values.
|
||||
/// When initialized, all keys will be created as configured. If an instance is removed,
|
||||
|
@ -215,7 +220,9 @@ namespace BirthdayBot
|
|||
{
|
||||
_shards[dead].Dispose();
|
||||
_shards[dead] = null;
|
||||
_destroyedShards++;
|
||||
}
|
||||
if (_destroyedShards > MaxDestroyedShards) Program.ProgramStop();
|
||||
|
||||
// Start up any missing shards
|
||||
int startAllowance = 4;
|
||||
|
|
Loading…
Reference in a new issue