trader.daemon.backoff module¶
Exponential backoff after a failed cycle.
Pure by design: this computes delays and never sleeps. The loop owns sleeping, which is what lets the growth sequence be asserted directly instead of being inferred from elapsed time.
- class trader.daemon.backoff.Backoff(*, base_seconds, max_seconds)[source]¶
Bases:
objectDoubling delay with a ceiling, reset by a success.
- Parameters:
base_seconds (int) – the delay after the first failure.
max_seconds (int) – the ceiling. Must not be below base_seconds — a lower ceiling makes every delay equal to the ceiling, so the delay never grows and the backoff is decorative.
- property consecutive_failures: int¶
How many failures since the last success. For the log line.
- next_delay()[source]¶
Record a failure and return how long to wait before retrying.
The exponent is clamped before the shift rather than after. A daemon that has been failing all day would otherwise compute base * 2**2000 — a perfectly valid Python integer that costs real time and memory to build, only to be thrown away by min.
- Return type:
int