Files
SocialPub/PrivaPub/Infrastructure/Jobs/Backoff.cs
T

13 lines
447 B
C#
Raw Normal View History

namespace PrivaPub.Infrastructure.Jobs
{
public static class Backoff
{
public static TimeSpan After(int attempt) =>
TimeSpan.FromSeconds(Math.Pow(attempt, 4) + 15 + Random.Shared.Next(10) * (attempt + 1));
public static TimeSpan HostQuarantine(int consecutiveFailures, int threshold) =>
consecutiveFailures < threshold
? TimeSpan.Zero
: TimeSpan.FromHours(Math.Min(Math.Pow(2, consecutiveFailures - threshold), 24 * 7));
}
}