PluralKit/Myriad/Gateway/Limit/TwilightGatewayRatelimiter.cs

33 lines
967 B
C#
Raw Permalink 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(30) };
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);
2021-12-24 03:02:45 +00:00
await _httpClient.GetAsync(_url + "?shard=" + shard);
return;
}
2021-12-24 03:02:45 +00:00
catch (TaskCanceledException)
{
_logger.Warning("Shard {ShardId}: Gateway queue timed out, retrying", shard);
}
2021-06-09 14:22:10 +00:00
}
}