retry v0.13.0 Retry.DelayStreams View Source
This module provide a set of helper functions that produce delay streams for
use with retry
.
Link to this section Summary
Functions
Returns a stream that is the same as delays
except that the delays never
exceed max
. This allow capping the delay between attempts to some max value.
Returns a constant stream of delays.
Returns a stream of delays that increase exponentially.
Returns a delay stream that is the same as delays
except it limits the total
life span of the stream to time_budget
. This calculation takes the execution
time of the block being retried into account.
Returns a stream of delays that increase exponentially.
Returns a stream in which each element of delays
is randomly adjusted to a number
between 1 and the original delay.
Returns a stream of delays that increase linearly.
Returns a stream of delays that increase linearly.
Returns a stream in which each element of delays
is randomly adjusted no
more than proportion
of the delay.
Link to this section Functions
cap(delays, max)
View Source
cap(Enumerable.t(), pos_integer()) :: Enumerable.t()
cap(Enumerable.t(), pos_integer()) :: Enumerable.t()
Returns a stream that is the same as delays
except that the delays never
exceed max
. This allow capping the delay between attempts to some max value.
Example
retry with: exponential_backoff() |> cap(10_000) do
# ...
end
Produces an exponentially increasing delay stream until the delay reaches 10 seconds at which point it stops increasing
constant_backoff(delay \\ 100)
View Source
constant_backoff(pos_integer()) :: Enumerable.t()
constant_backoff(pos_integer()) :: Enumerable.t()
Returns a constant stream of delays.
Example
retry with: constant_backoff(50) do
# ...
end
exp_backoff(initial_delay \\ 10)
View Source
exp_backoff(pos_integer()) :: Enumerable.t()
exp_backoff(pos_integer()) :: Enumerable.t()
Returns a stream of delays that increase exponentially.
Example
retry with: exp_backoff do
# ...
end
expiry(delays, time_budget, min_delay \\ 100)
View Source
expiry(Enumerable.t(), pos_integer(), pos_integer()) :: Enumerable.t()
expiry(Enumerable.t(), pos_integer(), pos_integer()) :: Enumerable.t()
Returns a delay stream that is the same as delays
except it limits the total
life span of the stream to time_budget
. This calculation takes the execution
time of the block being retried into account.
The execution of the code within the block will not be interrupted, so
the total time of execution may run over the time_budget
depending on how
long a single try will take.
Optionally, you can specify a minimum delay so the smallest value doesn't go below the threshold.
Example
retry with: exponential_backoff() |> expiry(1_000) do
# ...
end
Produces a delay stream that ends after 1 second has elapsed since its creation.
exponential_backoff(initial_delay \\ 10, factor \\ 2)
View Source
exponential_backoff(pos_integer(), pos_integer()) :: Enumerable.t()
exponential_backoff(pos_integer(), pos_integer()) :: Enumerable.t()
Returns a stream of delays that increase exponentially.
Example
retry with: exponential_backoff do
# ...
end
jitter(delays)
View Source
jitter(Enumerable.t()) :: Enumerable.t()
jitter(Enumerable.t()) :: Enumerable.t()
Returns a stream in which each element of delays
is randomly adjusted to a number
between 1 and the original delay.
Example
retry with: exponential_backoff() |> jitter() do
# ...
end
lin_backoff(initial_delay, factor)
View Source
lin_backoff(pos_integer(), pos_integer()) :: Enumerable.t()
lin_backoff(pos_integer(), pos_integer()) :: Enumerable.t()
Returns a stream of delays that increase linearly.
Example
retry with: lin_backoff(@fibonacci) do
# ...
end
linear_backoff(initial_delay, factor)
View Source
linear_backoff(pos_integer(), pos_integer()) :: Enumerable.t()
linear_backoff(pos_integer(), pos_integer()) :: Enumerable.t()
Returns a stream of delays that increase linearly.
Example
retry with: linear_backoff(50, 2) do
# ...
end
randomize(delays, proportion \\ 0.1)
View Source
randomize(Enumerable.t(), float()) :: Enumerable.t()
randomize(Enumerable.t(), float()) :: Enumerable.t()
Returns a stream in which each element of delays
is randomly adjusted no
more than proportion
of the delay.
Example
retry with: exponential_backoff() |> randomize do
# ...
end
Produces an exponentially increasing delay stream where each delay is randomly adjusted to be within 10 percent of the original value