102 std::size_t max_attempts,
125 std::size_t max_attempts,
126 std::chrono::milliseconds initial_delay,
127 std::chrono::milliseconds max_delay = std::chrono::milliseconds::max()) ->
retry_policy
154 std::size_t max_attempts,
155 std::chrono::milliseconds initial_delay = std::chrono::milliseconds(100),
156 double multiplier = 2.0,
157 std::chrono::milliseconds max_delay = std::chrono::milliseconds(30000),
281 return std::chrono::milliseconds(0);
284 std::chrono::milliseconds
delay;
293 delay = std::chrono::milliseconds(
301 auto calculated =
static_cast<long long>(
304 delay = std::chrono::milliseconds(calculated);
309 delay = std::chrono::milliseconds(0);
331 return "retry_policy(none)";
333 return "retry_policy(fixed, attempts=" + std::to_string(
max_attempts_) +
336 return "retry_policy(linear, attempts=" + std::to_string(
max_attempts_) +
339 return "retry_policy(exponential, attempts=" + std::to_string(
max_attempts_) +
341 "ms, multiplier=" + std::to_string(
multiplier_) +
")";
343 return "retry_policy(unknown)";
Encapsulates retry behavior configuration for jobs.
std::size_t max_attempts_
std::chrono::milliseconds max_delay_
auto reset() -> void
Resets the attempt counter to zero.
auto get_max_delay() const -> std::chrono::milliseconds
Gets the maximum delay cap.
auto record_attempt() -> void
Increments the attempt counter.
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.
std::size_t current_attempt_
std::chrono::milliseconds initial_delay_
auto has_attempts_remaining() const -> bool
Checks if more retry attempts are available.
static auto fixed(std::size_t max_attempts, std::chrono::milliseconds delay) -> retry_policy
Creates a fixed delay retry policy.
auto get_strategy() const -> retry_strategy
Gets the retry strategy type.
auto get_current_attempt() const -> std::size_t
Gets the current attempt number (0-based).
auto get_delay_for_current_attempt() const -> std::chrono::milliseconds
Calculates the delay for the current retry attempt.
auto uses_jitter() const -> bool
Checks if jitter is enabled.
retry_policy()
Default constructor creates a "no retry" policy.
auto is_retry_enabled() const -> bool
Checks if retry is enabled.
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.
static auto no_retry() -> retry_policy
Creates a policy that disables retry.
auto to_string() const -> std::string
Provides a string representation of the policy.
auto get_initial_delay() const -> std::chrono::milliseconds
Gets the initial delay between retries.
auto get_max_attempts() const -> std::size_t
Gets the maximum number of attempts.
auto get_multiplier() const -> double
Gets the multiplier used for exponential backoff.
@ delay
Delay processing (attempt later)
@ none
Below low_watermark, queue is healthy.
Core threading foundation of the thread system library.
retry_strategy
Defines the strategy for calculating delay between retry attempts.
@ linear
Linearly increasing delay.
@ exponential_backoff
Exponentially increasing delay with optional jitter.
@ fixed
Fixed delay between retries.