Add HTTP timeout/retry to Twilight rate limiter

This commit is contained in:
Ske 2021-08-12 08:59:48 +02:00
parent b5ce541440
commit 8de6960335

View File

@ -1,4 +1,5 @@
using System.Net.Http; using System;
using System.Net.Http;
using System.Threading.Tasks; using System.Threading.Tasks;
using Serilog; using Serilog;
@ -9,7 +10,10 @@ namespace Myriad.Gateway.Limit
{ {
private readonly string _url; private readonly string _url;
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly HttpClient _httpClient = new(); private readonly HttpClient _httpClient = new()
{
Timeout = TimeSpan.FromSeconds(60)
};
public TwilightGatewayRatelimiter(ILogger logger, string url) public TwilightGatewayRatelimiter(ILogger logger, string url)
{ {
@ -19,9 +23,19 @@ namespace Myriad.Gateway.Limit
public async Task Identify(int shard) public async Task Identify(int shard)
{ {
// Literally just request and wait :p while (true)
_logger.Information("Shard {ShardId}: Requesting identify at gateway queue {GatewayQueueUrl}", shard, _url); {
try
{
_logger.Information("Shard {ShardId}: Requesting identify at gateway queue {GatewayQueueUrl}",
shard, _url);
await _httpClient.GetAsync(_url); await _httpClient.GetAsync(_url);
return;
}
catch (TimeoutException)
{
}
}
} }
} }
} }