OnceMore

A flexible retry library for Elixir with composable backoff strategies.

OnceMore allows you to easily retry operations that may fail temporarily, such as network requests or distributed system operations. It supports both simple retries and stateful retries with an accumulator.

Installation

Add once_more to your list of dependencies in mix.exs:

def deps do
  [
    {:once_more, "~> 1.0.0"}
  ]
end

Features

Quick start

import OnceMore.DelayStreams

# Basic retry with exponential backoff
OnceMore.retry(
  fn -> make_network_call() end,
  &match?({:error, _}, &1),
  Stream.take(exponential_backoff(), 5)
)

# Retry with accumulator to track state
OnceMore.retry_with_acc(
  fn attempts -> {network_call(), attempts + 1} end,
  fn result, _attempts -> match?({:error, _}, result) end,
  0,
  Stream.take(constant_backoff(), 5)
)

# Common delay patterns can be composed:
50                        # Start with 50ms delay
|> exponential_backoff()  # Increase exponentially
|> randomize(0.2)         # Add some randomization
|> cap(1_000)             # Cap at 1 second
|> Stream.take(5)         # Limit to 5 attempts

Full documentation can be found at https://hexdocs.pm/once_more.

License

Licensed under the Apache License, Version 2.0. See LICENSE for details.