mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 04:56:49 +00:00
Add HTTP timeout/retry to Twilight rate limiter
This commit is contained in:
parent
b5ce541440
commit
8de6960335
1 changed files with 19 additions and 5 deletions
|
|
@ -1,4 +1,5 @@
|
|||
using System.Net.Http;
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Serilog;
|
||||
|
|
@ -9,7 +10,10 @@ namespace Myriad.Gateway.Limit
|
|||
{
|
||||
private readonly string _url;
|
||||
private readonly ILogger _logger;
|
||||
private readonly HttpClient _httpClient = new();
|
||||
private readonly HttpClient _httpClient = new()
|
||||
{
|
||||
Timeout = TimeSpan.FromSeconds(60)
|
||||
};
|
||||
|
||||
public TwilightGatewayRatelimiter(ILogger logger, string url)
|
||||
{
|
||||
|
|
@ -19,9 +23,19 @@ namespace Myriad.Gateway.Limit
|
|||
|
||||
public async Task Identify(int shard)
|
||||
{
|
||||
// Literally just request and wait :p
|
||||
_logger.Information("Shard {ShardId}: Requesting identify at gateway queue {GatewayQueueUrl}", shard, _url);
|
||||
await _httpClient.GetAsync(_url);
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger.Information("Shard {ShardId}: Requesting identify at gateway queue {GatewayQueueUrl}",
|
||||
shard, _url);
|
||||
await _httpClient.GetAsync(_url);
|
||||
return;
|
||||
}
|
||||
catch (TimeoutException)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue