Path: redb-route/redb.Route/Core/BackoffSchedule.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route/Core/BackoffSchedule.cs
----
namespace redb.Route.Core;
///
/// A pause that grows after each failed attempt: , then multiplied by each
/// time, never longer than . Shared by the start retry of a consumer
/// () and the reconnect of a lost connection
/// (), so both count their pauses the same way.
///
internal readonly record struct BackoffSchedule(TimeSpan First, double Multiplier, TimeSpan Max)
{
/// The pause after has passed and the attempt after it failed too.
public TimeSpan Next(TimeSpan current) =>
TimeSpan.FromTicks((long)Math.Min(current.Ticks * Multiplier, Max.Ticks));
///
/// Checks the three values of a schedule configured under ; the messages name the
/// configuration key (ConsumerStartRetry.Delay, Reconnect.MaxDelay).
///
public static void Validate(string section, TimeSpan first, double multiplier, TimeSpan max)
{
if (first <= TimeSpan.Zero)
throw new ArgumentOutOfRangeException("Delay", first, $"{section}.Delay must be positive.");
if (max < first)
throw new ArgumentOutOfRangeException("MaxDelay", max, $"{section}.MaxDelay must not be shorter than Delay.");
if (max.TotalMilliseconds > int.MaxValue)
throw new ArgumentOutOfRangeException("MaxDelay", max, $"{section}.MaxDelay must not exceed 24 days.");
if (double.IsNaN(multiplier) || multiplier < 1.0)
throw new ArgumentOutOfRangeException("Multiplier", multiplier, $"{section}.Multiplier must be 1 or more.");
}
}