Check connection no more than once every 30 seconds

This commit is contained in:
benbierens 2024-02-19 15:59:49 +01:00
parent 23b7bbd548
commit a6fce1084d
No known key found for this signature in database
GPG Key ID: 877D2C2E09A22F3A
1 changed files with 6 additions and 1 deletions

View File

@ -1,5 +1,4 @@
using ArgsUniform;
using GethConnector;
using Logging;
using Utils;
@ -12,6 +11,7 @@ namespace TestNetRewarder
public static CancellationToken CancellationToken { get; private set; }
public static BotClient BotClient { get; private set; } = null!;
private static Processor processor = null!;
private static DateTime lastCheck = DateTime.MinValue;
public static Task Main(string[] args)
{
@ -65,6 +65,9 @@ namespace TestNetRewarder
private static async Task EnsureBotOnline()
{
var start = DateTime.UtcNow;
var timeSince = start - lastCheck;
if (timeSince.TotalSeconds < 30.0) return;
while (! await BotClient.IsOnline() && !CancellationToken.IsCancellationRequested)
{
await Task.Delay(5000);
@ -77,6 +80,8 @@ namespace TestNetRewarder
throw new Exception(msg);
}
}
lastCheck = start;
}
private static void PrintHelp()