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()
|
public async Task Stop()
|
||||||
{
|
{
|
||||||
if (stopped) return;
|
if (stopped) return;
|
||||||
Client.StopReceiving();
|
Client?.StopReceiving();
|
||||||
timeoutWaitTaskToken.Cancel();
|
timeoutWaitTaskToken?.Cancel();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await timeoutWaitTask;
|
if (timeoutWaitTask != null)
|
||||||
|
await timeoutWaitTask;
|
||||||
}
|
}
|
||||||
catch (OperationCanceledException) { }
|
catch (OperationCanceledException) { }
|
||||||
await Timeout.Save();
|
await Timeout?.Save();
|
||||||
Dispose();
|
Dispose();
|
||||||
stopped = true;
|
stopped = true;
|
||||||
}
|
}
|
||||||
@ -119,8 +120,8 @@ namespace JetKarmaBot
|
|||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
timeoutWaitTaskToken.Dispose();
|
timeoutWaitTaskToken?.Dispose();
|
||||||
timeoutWaitTask.Dispose();
|
timeoutWaitTask?.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@ -42,14 +42,13 @@ namespace JetKarmaBot
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
bot.Init().Wait();
|
bot.Init().GetAwaiter().GetResult();
|
||||||
log.Info("JetKarmaBot started. Press Ctrl-C to exit...");
|
log.Info("JetKarmaBot started. Press Ctrl-C to exit...");
|
||||||
Environment.ExitCode = (int)ExitCode.ErrorRunning;
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
log.Error(ex);
|
log.Error(ex);
|
||||||
Environment.ExitCode = (int)ExitCode.ErrorException;
|
return (int)ExitCode.ErrorException;
|
||||||
}
|
}
|
||||||
ManualResetEvent quitEvent = new ManualResetEvent(false);
|
ManualResetEvent quitEvent = new ManualResetEvent(false);
|
||||||
try
|
try
|
||||||
@ -62,14 +61,14 @@ namespace JetKarmaBot
|
|||||||
AppDomain.CurrentDomain.ProcessExit += (sender, args) =>
|
AppDomain.CurrentDomain.ProcessExit += (sender, args) =>
|
||||||
{
|
{
|
||||||
log.Info("Received stop request, waiting for exit...");
|
log.Info("Received stop request, waiting for exit...");
|
||||||
bot?.Stop()?.Wait();
|
bot?.Stop()?.GetAwaiter().GetResult();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
catch { }
|
catch { }
|
||||||
|
|
||||||
quitEvent.WaitOne(Timeout.Infinite);
|
quitEvent.WaitOne(Timeout.Infinite);
|
||||||
log.Info("Waiting for exit...");
|
log.Info("Waiting for exit...");
|
||||||
bot?.Stop()?.Wait();
|
bot?.Stop()?.GetAwaiter().GetResult();
|
||||||
|
|
||||||
return (int)ExitCode.Ok;
|
return (int)ExitCode.Ok;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user