mirror of
https://github.com/Jetsparrow/karmabot.git
synced 2026-01-21 00:56:09 +03:00
bail on error immediately
This commit is contained in:
parent
6ff22680b9
commit
58f7e17ba6
@ -59,14 +59,15 @@ namespace JetKarmaBot
|
||||
public async Task Stop()
|
||||
{
|
||||
if (stopped) return;
|
||||
Client.StopReceiving();
|
||||
timeoutWaitTaskToken.Cancel();
|
||||
Client?.StopReceiving();
|
||||
timeoutWaitTaskToken?.Cancel();
|
||||
try
|
||||
{
|
||||
if (timeoutWaitTask != null)
|
||||
await timeoutWaitTask;
|
||||
}
|
||||
catch (OperationCanceledException) { }
|
||||
await Timeout.Save();
|
||||
await Timeout?.Save();
|
||||
Dispose();
|
||||
stopped = true;
|
||||
}
|
||||
@ -119,8 +120,8 @@ namespace JetKarmaBot
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
timeoutWaitTaskToken.Dispose();
|
||||
timeoutWaitTask.Dispose();
|
||||
timeoutWaitTaskToken?.Dispose();
|
||||
timeoutWaitTask?.Dispose();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@ -42,14 +42,13 @@ namespace JetKarmaBot
|
||||
|
||||
try
|
||||
{
|
||||
bot.Init().Wait();
|
||||
bot.Init().GetAwaiter().GetResult();
|
||||
log.Info("JetKarmaBot started. Press Ctrl-C to exit...");
|
||||
Environment.ExitCode = (int)ExitCode.ErrorRunning;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.Error(ex);
|
||||
Environment.ExitCode = (int)ExitCode.ErrorException;
|
||||
return (int)ExitCode.ErrorException;
|
||||
}
|
||||
ManualResetEvent quitEvent = new ManualResetEvent(false);
|
||||
try
|
||||
@ -62,14 +61,14 @@ namespace JetKarmaBot
|
||||
AppDomain.CurrentDomain.ProcessExit += (sender, args) =>
|
||||
{
|
||||
log.Info("Received stop request, waiting for exit...");
|
||||
bot?.Stop()?.Wait();
|
||||
bot?.Stop()?.GetAwaiter().GetResult();
|
||||
};
|
||||
}
|
||||
catch { }
|
||||
|
||||
quitEvent.WaitOne(Timeout.Infinite);
|
||||
log.Info("Waiting for exit...");
|
||||
bot?.Stop()?.Wait();
|
||||
bot?.Stop()?.GetAwaiter().GetResult();
|
||||
|
||||
return (int)ExitCode.Ok;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user