Re-add rate limit margins

This commit is contained in:
Tyrrrz
2022-12-15 20:40:28 +02:00
parent 2c4f812d4f
commit b138908eb3
3 changed files with 32 additions and 2 deletions

View File

@@ -0,0 +1,17 @@
using System;
namespace DiscordChatExporter.Core.Utils.Extensions;
public static class TimeSpanExtensions
{
public static TimeSpan Clamp(this TimeSpan value, TimeSpan min, TimeSpan max)
{
if (value < min)
return min;
if (value > max)
return max;
return value;
}
}

View File

@@ -41,7 +41,10 @@ public static class Http
{
// If rate-limited, use retry-after header as the guide
if (result.Result.Headers.RetryAfter?.Delta is { } retryAfter)
return retryAfter;
{
// Add some buffer just in case
return retryAfter + TimeSpan.FromSeconds(1);
}
return TimeSpan.FromSeconds(Math.Pow(2, i) + 1);
},