From 8418a755d06b7a14519dd2f00b216b5dc046a3df Mon Sep 17 00:00:00 2001 From: Parker Selbert Date: Wed, 7 Feb 2024 17:02:56 -0600 Subject: [PATCH] Configure retry backoff at compile time The option makes testing with_retry much faster, but it isn't documented for the time being. --- config/config.exs | 2 ++ lib/oban/backoff.ex | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/config/config.exs b/config/config.exs index baca66e1..2215e369 100644 --- a/config/config.exs +++ b/config/config.exs @@ -4,6 +4,8 @@ config :elixir, :time_zone_database, Tz.TimeZoneDatabase config :logger, level: :warning +config :oban, Oban.Backoff, retry_mult: 1 + config :oban, Oban.Test.Repo, migration_lock: false, name: Oban.Test.Repo, diff --git a/lib/oban/backoff.ex b/lib/oban/backoff.ex index bbf04b05..9c8dd365 100644 --- a/lib/oban/backoff.ex +++ b/lib/oban/backoff.ex @@ -3,6 +3,8 @@ defmodule Oban.Backoff do @type jitter_mode :: :inc | :dec | :both + @retry_mult Application.compile_env(:oban, [Oban.Backoff, :retry_mult], 100) + @doc """ Calculate an exponential backoff in seconds for a given attempt. @@ -115,7 +117,7 @@ defmodule Oban.Backoff do defp retry_or_raise(fun, retries, attempt, kind, reason, stacktrace) do if retries == :infinity or attempt < retries do attempt - |> exponential(mult: 100) + |> exponential(mult: @retry_mult) |> jitter() |> Process.sleep()