make socket disconnect check configurable

This commit is contained in:
13xforever 2021-06-15 12:01:35 +05:00
parent 212dffb80f
commit 9a303fe65a
2 changed files with 3 additions and 3 deletions

View File

@ -57,6 +57,7 @@ namespace CompatBot
public static TimeSpan ModerationBacklogThresholdInHours => TimeSpan.FromHours(config.GetValue(nameof(ModerationBacklogThresholdInHours), 1));
public static TimeSpan DefaultTimeoutInSec => TimeSpan.FromSeconds(config.GetValue(nameof(DefaultTimeoutInSec), 30));
public static TimeSpan SocketDisconnectCheckIntervalInSec => TimeSpan.FromSeconds(config.GetValue(nameof(SocketDisconnectCheckIntervalInSec), 10));
public static TimeSpan LogParsingTimeoutInSec => TimeSpan.FromSeconds(config.GetValue(nameof(LogParsingTimeoutInSec), 30));
public static TimeSpan BuildTimeDifferenceForOutdatedBuildsInDays => TimeSpan.FromDays(config.GetValue(nameof(BuildTimeDifferenceForOutdatedBuildsInDays), 3));
public static TimeSpan ShutupTimeLimitInMin => TimeSpan.FromMinutes(config.GetValue(nameof(ShutupTimeLimitInMin), 5));

View File

@ -15,7 +15,6 @@ namespace CompatBot
{
internal static class Watchdog
{
private static readonly TimeSpan CheckInterval = TimeSpan.FromSeconds(10);
public static readonly ConcurrentQueue<DateTime> DisconnectTimestamps = new();
public static readonly Stopwatch TimeSinceLastIncomingMessage = Stopwatch.StartNew();
private static bool IsOk => DisconnectTimestamps.IsEmpty && TimeSinceLastIncomingMessage.Elapsed < Config.IncomingMessageCheckIntervalInMin;
@ -26,7 +25,7 @@ namespace CompatBot
discordClient = client;
do
{
await Task.Delay(CheckInterval, Config.Cts.Token).ConfigureAwait(false);
await Task.Delay(Config.SocketDisconnectCheckIntervalInSec, Config.Cts.Token).ConfigureAwait(false);
foreach (var sudoer in ModProvider.Mods.Values.Where(m => m.Sudoer))
{
var user = await client.GetUserAsync(sudoer.DiscordId).ConfigureAwait(false);
@ -49,7 +48,7 @@ namespace CompatBot
Config.TelemetryClient?.TrackEvent("socket-deadlock-potential");
Config.Log.Warn("Potential socket deadlock detected, reconnecting...");
await client.ReconnectAsync(true).ConfigureAwait(false);
await Task.Delay(CheckInterval, Config.Cts.Token).ConfigureAwait(false);
await Task.Delay(Config.SocketDisconnectCheckIntervalInSec, Config.Cts.Token).ConfigureAwait(false);
if (IsOk)
{
Config.Log.Info("Looks like we're back in business");