Skip to content

Commit

Permalink
Configure retry backoff at compile time
Browse files Browse the repository at this point in the history
The option makes testing with_retry much faster, but it isn't documented
for the time being.
  • Loading branch information
sorentwo committed Feb 7, 2024
1 parent c43e600 commit 8418a75
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion lib/oban/backoff.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit 8418a75

Please sign in to comment.