2021-06-09 14:22:10 +00:00
|
|
|
using Serilog;
|
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
namespace Myriad.Gateway.Limit;
|
|
|
|
|
|
|
|
public class TwilightGatewayRatelimiter: IGatewayRatelimiter
|
2021-06-09 14:22:10 +00:00
|
|
|
{
|
2021-11-27 02:10:56 +00:00
|
|
|
private readonly HttpClient _httpClient = new() { Timeout = TimeSpan.FromSeconds(60) };
|
2021-08-27 15:03:47 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
private readonly ILogger _logger;
|
|
|
|
private readonly string _url;
|
2021-06-09 14:22:10 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
public TwilightGatewayRatelimiter(ILogger logger, string url)
|
|
|
|
{
|
|
|
|
_url = url;
|
|
|
|
_logger = logger.ForContext<TwilightGatewayRatelimiter>();
|
|
|
|
}
|
|
|
|
|
|
|
|
public async Task Identify(int shard)
|
|
|
|
{
|
|
|
|
while (true)
|
|
|
|
try
|
2021-08-12 06:59:48 +00:00
|
|
|
{
|
2021-11-27 02:10:56 +00:00
|
|
|
_logger.Information("Shard {ShardId}: Requesting identify at gateway queue {GatewayQueueUrl}",
|
|
|
|
shard, _url);
|
|
|
|
await _httpClient.GetAsync(_url);
|
|
|
|
return;
|
2021-08-12 06:59:48 +00:00
|
|
|
}
|
2021-11-27 02:10:56 +00:00
|
|
|
catch (TimeoutException) { }
|
2021-06-09 14:22:10 +00:00
|
|
|
}
|
|
|
|
}
|