|
ORE Studio 0.0.4
|
Stateful exponential-backoff retry calculator. More...
#include <retry_strategy.hpp>

Public Member Functions | |
| retry_strategy (config cfg) | |
| void | on_start () |
| Record a successful start. | |
| std::chrono::seconds | on_failure () |
| Record a failure and compute the next backoff delay. | |
| bool | exceeded (int max) const |
Returns whether the failure count has reached or exceeded max. | |
| int | failure_count () const |
| Returns the current consecutive failure count. | |
| void | set_failure_count (int n) |
| Restore a previously saved failure count without resetting state. | |
| void | reset () |
| Reset the counter and start-time record to initial state. | |
Stateful exponential-backoff retry calculator.
Tracks the number of consecutive failures and the time of the last successful start, and computes the next wait interval as:
delay = min(initial_delay * 2^n, max_delay)
where n is the current failure count. If the elapsed time since the last start exceeds reset_threshold, the failure counter is reset before computing the delay — a long-running process that has an occasional transient crash restarts quickly instead of incurring a large penalty.
This class is a pure chrono utility: it has no knowledge of processes, services, or any external system. All logging and policy decisions belong to the caller.
| void on_start | ( | ) |
Record a successful start.
Must be called immediately after each successful launch so that on_failure() can measure elapsed uptime accurately.
| std::chrono::seconds on_failure | ( | ) |
Record a failure and compute the next backoff delay.
If the elapsed time since on_start() exceeds config.reset_threshold, the failure counter is reset to 0 before computing the delay. The counter is then incremented and the delay is returned.
| bool exceeded | ( | int | max | ) | const |
Returns whether the failure count has reached or exceeded max.
Call before on_failure() to decide if the threshold has been crossed on this failure, before the counter is incremented.
| void set_failure_count | ( | int | n | ) |
Restore a previously saved failure count without resetting state.
Used when a new entry must inherit an accumulated count from a prior one (e.g. after a process is relaunched and the entry is replaced).