using FinalFactory.Rendezvous.Contracts; namespace FinalFactory.Rendezvous.TestClient; internal sealed class HostServiceFailureBudget { private const int MaximumConsecutiveTransientFailures = 3; private int _consecutiveTransientFailures; internal bool ShouldStop( RendezvousErrorCode error, DateTimeOffset leaseExpiresAt, DateTimeOffset now) { if (error == RendezvousErrorCode.None) { Reset(); return false; } if (!IsTransient(error)) { return true; } _consecutiveTransientFailures++; return _consecutiveTransientFailures >= MaximumConsecutiveTransientFailures || now >= leaseExpiresAt; } internal void Reset() => _consecutiveTransientFailures = 0; private static bool IsTransient(RendezvousErrorCode error) => error is RendezvousErrorCode.RateLimited or RendezvousErrorCode.ServiceUnavailable or RendezvousErrorCode.InternalError; }