Schedules

object Schedules

Convenience methods to create common ZIO schedules for retrying

class Object
trait Matchable
class Any

Value members

Concrete methods

def common(min: Duration, max: Duration, factor: Double, retryImmediately: Boolean, maxRetries: Option[Int], jitterFactor: Double): Schedule[Any & Random, Any, (Any, Long)]

A common-practice schedule for retrying

A common-practice schedule for retrying

By default the first retry is done immediately. With transient / random failures this method gives the highest chance of fast success. After that Retry uses exponential backoff between some minimum and maximum duration. Jitter is added to prevent spikes of retries from multiple instances. An optional maximum number of retries ensures that retrying does not continue forever.

See also https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/

Value parameters:
factor

Factor with which delays increase

jitterFactor

Maximum fraction of the current delay interval that is randomly added or subtracted. This helps to spread call attempts in time when there are multiple systems making calls to some system using the same retry schedule. For example, with jitterFactor = 0.1 the retry intervals will be multiplied with a random factor between 0.9 and 1.1. jitterFactor = 0 disables jittering.

max

Maximum backoff time. When this value is reached, subsequent intervals will be equal to this value.

maxRetries

Maximum number of retries

min

Minimum retry backoff delay

retryImmediately

Retry immediately after the first failure

def exponentialBackoff[E](min: Duration, max: Duration, factor: Double): Schedule[Any, E, Duration]

Schedule for exponential backoff up to a maximum interval

Schedule for exponential backoff up to a maximum interval

Type parameters:
E

Schedule input

Value parameters:
factor

Exponential factor. 2 means doubling, 1 is constant, < 1 means decreasing

max

Maximum backoff time. When this value is reached, subsequent intervals will be equal to this value.

min

Minimum backoff time

def whenCase[Env, In, Out](pf: PartialFunction[In, Any])(schedule: Schedule[Env, In, Out]): Schedule[Env, In, (In, Out)]

Apply the given schedule only when inputs match the partial function

Apply the given schedule only when inputs match the partial function