Skip to content

Commit

Permalink
Backoff retry on db errors from GenServer calls
Browse files Browse the repository at this point in the history
GenServer calls that result in a `ConnectionError` or `Postgrex.Error`
should also be caught and retried rather than crashing on the first
attempt.
  • Loading branch information
sorentwo committed Mar 25, 2024
1 parent 8ae1188 commit c875bfd
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/oban/backoff.ex
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,15 @@ defmodule Oban.Backoff do
with_retry(fun, retries, 1)
end

@db_errors [DBConnection.ConnectionError, Postgrex.Error]

defp with_retry(fun, retries, attempt) do
fun.()
rescue
error in [DBConnection.ConnectionError, Postgrex.Error] ->
error in @db_errors ->
retry_or_raise(fun, retries, attempt, :error, error, __STACKTRACE__)
catch
:exit, {:timeout, _} = reason ->
:exit, {error, _} = reason when error in [:timeout | @db_errors] ->
retry_or_raise(fun, retries, attempt, :exit, reason, __STACKTRACE__)
end

Expand Down

0 comments on commit c875bfd

Please sign in to comment.