|
Thread System 0.3.1
High-performance C++20 thread pool with work stealing and DAG scheduling
|
Encapsulates retry behavior configuration for jobs. More...
#include <retry_policy.h>

Public Member Functions | |
| retry_policy () | |
| Default constructor creates a "no retry" policy. | |
| auto | get_strategy () const -> retry_strategy |
| Gets the retry strategy type. | |
| auto | get_max_attempts () const -> std::size_t |
| Gets the maximum number of attempts. | |
| auto | get_initial_delay () const -> std::chrono::milliseconds |
| Gets the initial delay between retries. | |
| auto | get_multiplier () const -> double |
| Gets the multiplier used for exponential backoff. | |
| auto | get_max_delay () const -> std::chrono::milliseconds |
| Gets the maximum delay cap. | |
| auto | uses_jitter () const -> bool |
| Checks if jitter is enabled. | |
| auto | is_retry_enabled () const -> bool |
| Checks if retry is enabled. | |
| auto | get_current_attempt () const -> std::size_t |
| Gets the current attempt number (0-based). | |
| auto | has_attempts_remaining () const -> bool |
| Checks if more retry attempts are available. | |
| auto | record_attempt () -> void |
| Increments the attempt counter. | |
| auto | reset () -> void |
| Resets the attempt counter to zero. | |
| auto | get_delay_for_current_attempt () const -> std::chrono::milliseconds |
| Calculates the delay for the current retry attempt. | |
| auto | to_string () const -> std::string |
| Provides a string representation of the policy. | |
Static Public Member Functions | |
| static auto | no_retry () -> retry_policy |
| Creates a policy that disables retry. | |
| static auto | fixed (std::size_t max_attempts, std::chrono::milliseconds delay) -> retry_policy |
| Creates a fixed delay retry policy. | |
| static auto | linear (std::size_t max_attempts, std::chrono::milliseconds initial_delay, std::chrono::milliseconds max_delay=std::chrono::milliseconds::max()) -> retry_policy |
| Creates a linear backoff retry policy. | |
| static auto | exponential_backoff (std::size_t max_attempts, std::chrono::milliseconds initial_delay=std::chrono::milliseconds(100), double multiplier=2.0, std::chrono::milliseconds max_delay=std::chrono::milliseconds(30000), bool use_jitter=false) -> retry_policy |
| Creates an exponential backoff retry policy. | |
Private Attributes | |
| retry_strategy | strategy_ |
| std::size_t | max_attempts_ |
| std::chrono::milliseconds | initial_delay_ |
| double | multiplier_ |
| std::chrono::milliseconds | max_delay_ |
| bool | use_jitter_ |
| std::size_t | current_attempt_ |
Encapsulates retry behavior configuration for jobs.
The retry_policy class provides a flexible way to configure how failed jobs should be retried. It supports multiple retry strategies:
Definition at line 66 of file retry_policy.h.
|
inline |
Default constructor creates a "no retry" policy.
Definition at line 72 of file retry_policy.h.
Referenced by no_retry().

|
inlinestaticnodiscard |
Creates an exponential backoff retry policy.
Delay doubles with each attempt: initial_delay * (multiplier ^ attempt)
| max_attempts | Maximum number of attempts (including initial) |
| initial_delay | Base delay for first retry (default: 100ms) |
| multiplier | Exponential multiplier (default: 2.0) |
| max_delay | Maximum delay cap (default: 30 seconds) |
| use_jitter | Add randomness to prevent thundering herd |
Definition at line 153 of file retry_policy.h.
References kcenon::thread::exponential_backoff, initial_delay_, max_attempts_, max_delay_, multiplier_, strategy_, and use_jitter_.
|
inlinestaticnodiscard |
Creates a fixed delay retry policy.
| max_attempts | Maximum number of attempts (including initial) |
| delay | Fixed delay between attempts |
Definition at line 101 of file retry_policy.h.
References kcenon::thread::delay, kcenon::thread::fixed, initial_delay_, max_attempts_, max_delay_, multiplier_, and strategy_.
|
inlinenodiscard |
Gets the current attempt number (0-based).
Definition at line 237 of file retry_policy.h.
References current_attempt_.
|
inlinenodiscard |
Calculates the delay for the current retry attempt.
Definition at line 277 of file retry_policy.h.
References current_attempt_, kcenon::thread::delay, kcenon::thread::exponential_backoff, kcenon::thread::fixed, initial_delay_, kcenon::thread::linear, max_delay_, multiplier_, kcenon::thread::none, and strategy_.
|
inlinenodiscard |
Gets the initial delay between retries.
Definition at line 192 of file retry_policy.h.
References initial_delay_.
|
inlinenodiscard |
Gets the maximum number of attempts.
Definition at line 183 of file retry_policy.h.
References max_attempts_.
|
inlinenodiscard |
Gets the maximum delay cap.
Definition at line 210 of file retry_policy.h.
References max_delay_.
|
inlinenodiscard |
Gets the multiplier used for exponential backoff.
Definition at line 201 of file retry_policy.h.
References multiplier_.
|
inlinenodiscard |
Gets the retry strategy type.
Definition at line 174 of file retry_policy.h.
References strategy_.
|
inlinenodiscard |
Checks if more retry attempts are available.
Definition at line 246 of file retry_policy.h.
References current_attempt_, and max_attempts_.
|
inlinenodiscard |
Checks if retry is enabled.
Definition at line 228 of file retry_policy.h.
References max_attempts_, kcenon::thread::none, and strategy_.
|
inlinestaticnodiscard |
Creates a linear backoff retry policy.
Delay increases linearly: delay * attempt_number
| max_attempts | Maximum number of attempts (including initial) |
| initial_delay | Base delay for first retry |
| max_delay | Maximum delay cap (default: no cap) |
Definition at line 124 of file retry_policy.h.
References initial_delay_, kcenon::thread::linear, max_attempts_, max_delay_, multiplier_, and strategy_.
|
inlinestaticnodiscard |
Creates a policy that disables retry.
Definition at line 87 of file retry_policy.h.
References retry_policy().

|
inline |
Increments the attempt counter.
Call this after each failed attempt. If the counter reaches max_attempts, has_attempts_remaining() will return false.
Definition at line 257 of file retry_policy.h.
References current_attempt_.
|
inline |
Resets the attempt counter to zero.
Definition at line 265 of file retry_policy.h.
References current_attempt_.
|
inlinenodiscard |
Provides a string representation of the policy.
Definition at line 326 of file retry_policy.h.
References kcenon::thread::exponential_backoff, kcenon::thread::fixed, initial_delay_, kcenon::thread::linear, max_attempts_, multiplier_, kcenon::thread::none, and strategy_.
|
inlinenodiscard |
Checks if jitter is enabled.
Definition at line 219 of file retry_policy.h.
References use_jitter_.
|
private |
Definition at line 354 of file retry_policy.h.
Referenced by get_current_attempt(), get_delay_for_current_attempt(), has_attempts_remaining(), record_attempt(), and reset().
|
private |
Definition at line 350 of file retry_policy.h.
Referenced by exponential_backoff(), fixed(), get_delay_for_current_attempt(), get_initial_delay(), linear(), and to_string().
|
private |
Definition at line 349 of file retry_policy.h.
Referenced by exponential_backoff(), fixed(), get_max_attempts(), has_attempts_remaining(), is_retry_enabled(), linear(), and to_string().
|
private |
Definition at line 352 of file retry_policy.h.
Referenced by exponential_backoff(), fixed(), get_delay_for_current_attempt(), get_max_delay(), and linear().
|
private |
Definition at line 351 of file retry_policy.h.
Referenced by exponential_backoff(), fixed(), get_delay_for_current_attempt(), get_multiplier(), linear(), and to_string().
|
private |
Definition at line 348 of file retry_policy.h.
Referenced by exponential_backoff(), fixed(), get_delay_for_current_attempt(), get_strategy(), is_retry_enabled(), linear(), and to_string().
|
private |
Definition at line 353 of file retry_policy.h.
Referenced by exponential_backoff(), and uses_jitter().