RetryPolicy

data class RetryPolicy(val maxRetries: Int = 2, val initialBackoff: Duration = 500.milliseconds, val maxBackoff: Duration = 5.seconds, val jitter: Double = 0.25, val retryStatuses: Set<Int> = DEFAULT_RETRY_STATUSES, val respectRetryAfter: Boolean = true, val maxRetryAfter: Duration = 60.seconds, val retryOnConnectionError: Boolean = true, val retryOnTimeout: Boolean = true)(source)

When and how failed requests are retried. The defaults match the official JS SDK: two retries, 0.5 s backoff doubling to a 5 s cap with up to 25% subtracted as jitter, and server retry-after-ms / Retry-After hints honored up to maxRetryAfter. The Python SDK shares the retries, backoff and statuses but doesn't cap hints, and adds a 30 s budget per call, which jev4k doesn't have: timeout applies per attempt.

Java can't call the full constructor or copy, whose Duration parameters Kotlin hides from it. It starts from the no-argument new RetryPolicy() and changes one setting at a time with the with… methods, which take milliseconds: new RetryPolicy().withMaxRetries(4).withInitialBackoffMillis(250). To move both backoff limits, use withBackoffMillis, which checks them together.

Constructors

Link copied to clipboard
constructor(maxRetries: Int = 2, initialBackoff: Duration = 500.milliseconds, maxBackoff: Duration = 5.seconds, jitter: Double = 0.25, retryStatuses: Set<Int> = DEFAULT_RETRY_STATUSES, respectRetryAfter: Boolean = true, maxRetryAfter: Duration = 60.seconds, retryOnConnectionError: Boolean = true, retryOnTimeout: Boolean = true)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
fun backoff(retryNumber: Int, random: Double): Duration

The delay before retry number retryNumber (1-based): min(initial * 2^(n-1), max), reduced by jitter * random of itself. random is a value in 0.0..1.0.

Link copied to clipboard
fun withBackoffMillis(initialMillis: Long, maxMillis: Long): RetryPolicy

A copy with both initialBackoff and maxBackoff changed, in milliseconds. Changed one at a time, they can fail on the way, when a new value passes the other's old one.

Link copied to clipboard

A copy with initialBackoff changed, in milliseconds.

Link copied to clipboard

A copy with jitter changed.

Link copied to clipboard

A copy with maxBackoff changed, in milliseconds.

Link copied to clipboard
fun withMaxRetries(maxRetries: Int): RetryPolicy

A copy with maxRetries changed.

Link copied to clipboard

A copy with maxRetryAfter changed, in milliseconds.

Link copied to clipboard
fun withRespectRetryAfter(respectRetryAfter: Boolean): RetryPolicy

A copy with respectRetryAfter changed.

Link copied to clipboard
fun withRetryOnConnectionError(retryOnConnectionError: Boolean): RetryPolicy

A copy with retryOnConnectionError changed.

Link copied to clipboard
fun withRetryOnTimeout(retryOnTimeout: Boolean): RetryPolicy

A copy with retryOnTimeout changed.

Link copied to clipboard
fun withRetryStatuses(retryStatuses: Set<Int>): RetryPolicy

A copy with retryStatuses changed.