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