elixir_retry v0.3.0 Retry.DelayStreams

This module provide a set of helper functions that produce delay streams for use with retry.

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 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 linearly

Returns a stream in which each element of delays is randomly adjusted no more than proportion of the delay

Functions

cap(delays, max)

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 exp_backoff |> cap(10_000) do
  # ...
end

Produces an exponentially increasing delay stream until the delay reaches 10 seconds at which point it stops increasing

exp_backoff()

Returns a stream of delays that increase exponentially.

Example

retry exp_backoff do
  # ...
end
expiry(delays, time_budget)

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.

Example

retry exp_backoff |> expiry(1000) do
  # ...
end

Produces a delay stream that ends after 1 second has elapsed since its creation.

lin_backoff(initial_delay, factor)

Returns a stream of delays that increase linearly.

Example

retry lin_backoff(@fibonacci) do
  # ...
end
randomize(delays, proportion \\ 0.1)

Returns a stream in which each element of delays is randomly adjusted no more than proportion of the delay.

Example

retry exp_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