RetryPolicy

class RetryPolicy(val maxAttempts: Int, val strategy: DelayStrategy = DelayStrategy.EXPONENTIAL, val baseDelaySeconds: Double = 10.0, val maxDelaySeconds: Double = 300.0, val unknownFailurePolicy: UnknownFailurePolicy = UnknownFailurePolicy.CONSERVATIVE)

Runtime policy consumed by the retry wrapper. Translates an observed failure into "should we retry now?" + "if so, wait how long?".

attemptIndex is 0-based throughout: 0 means "the original attempt has just failed; should we retry once?"; 1 means "the first retry has just failed; should we retry again?"; etc.

Constructors

Link copied to clipboard
constructor(maxAttempts: Int, strategy: DelayStrategy = DelayStrategy.EXPONENTIAL, baseDelaySeconds: Double = 10.0, maxDelaySeconds: Double = 300.0, unknownFailurePolicy: UnknownFailurePolicy = UnknownFailurePolicy.CONSERVATIVE)

Types

Link copied to clipboard
object Companion

Predefined RetryPolicy instances.

Properties

Link copied to clipboard

Base delay in seconds, used as the starting point by every DelayStrategy.

Link copied to clipboard

Maximum number of retries after the original attempt (the original attempt itself is not counted).

Link copied to clipboard
val maxDelaySeconds: Double = 300.0

Upper bound in seconds that any computed delay is clamped to.

Link copied to clipboard

Per-attempt delay growth strategy applied between retries.

Link copied to clipboard

How failures of TransiencyLevel.UNKNOWN transiency are treated.

Functions

Link copied to clipboard
fun nextDelay(attemptIndex: Int): Duration

Computes the wall-clock delay before the next retry attempt, per the configured strategy and capped at maxDelaySeconds.

Link copied to clipboard
fun shouldRetry(failure: AnalyzedFailure, attemptIndex: Int): Boolean

Returns true if the policy decides to retry after this particular failure.