rays/retry
How long to wait before trying again something that failed, such as a
Durable Object alarm registered with durable_object.register_alarm.
import gleam/time/duration
import rays/retry
// 2s, 4s, 8s, ... and then 10 minutes between every attempt.
retry.Exponential(first: duration.seconds(2), max: duration.minutes(10))
// A minute between every attempt.
retry.Fixed(every: duration.minutes(1))
Types
How long to wait between attempts of work that failed.
pub type Backoff {
Exponential(first: duration.Duration, max: duration.Duration)
Fixed(every: duration.Duration)
}
Constructors
-
Exponential(first: duration.Duration, max: duration.Duration)Wait
firstafter the first failed attempt, then twice as long after each one after it, up tomax. -
Fixed(every: duration.Duration)Wait the same time after every failed attempt.
Values
pub fn delay(
backoff: Backoff,
after attempt: Int,
) -> duration.Duration
How long to wait after the given attempt failed, counting the first attempt as 1, before making the next one.
Examples
let backoff =
retry.Exponential(first: duration.seconds(2), max: duration.seconds(5))
retry.delay(backoff, after: 1)
// -> duration.seconds(2)
retry.delay(backoff, after: 2)
// -> duration.seconds(4)
retry.delay(backoff, after: 3)
// -> duration.seconds(5)