PluralKit/Myriad/Gateway/Limit/TwilightGatewayRatelimiter.cs

30 lines
824 B
C#
Raw Normal View History

2021-06-09 14:22:10 +00:00
using Serilog;
namespace Myriad.Gateway.Limit;
public class TwilightGatewayRatelimiter: IGatewayRatelimiter
2021-06-09 14:22:10 +00:00
{
private readonly HttpClient _httpClient = new() { Timeout = TimeSpan.FromSeconds(60) };
2021-08-27 15:03:47 +00:00
private readonly ILogger _logger;
private readonly string _url;
2021-06-09 14:22:10 +00:00
public TwilightGatewayRatelimiter(ILogger logger, string url)
{
_url = url;
_logger = logger.ForContext<TwilightGatewayRatelimiter>();
}
public async Task Identify(int shard)
{
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
}
}