Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify only _some_ errors to be retried. #54

Open
rafal0p opened this issue Nov 20, 2022 · 2 comments
Open

Specify only _some_ errors to be retried. #54

rafal0p opened this issue Nov 20, 2022 · 2 comments

Comments

@rafal0p
Copy link

rafal0p commented Nov 20, 2022

Let's assume that we have a function like that:

 @spec foo() ::
         :ok
         | {:error, :some_retryable_reason}
         | {:error, :other_retryable_reason}
         | {:error, :some_non_retryable_reason}
         | {:error, :other_non_retryable_reason}
 def foo() do
   ...
 end

What I'd like to express is roughly this:

retry with: linear_backoff(50, 1) |> take(5),
      rescue_only: [
        {:error, :some_retryable_reason},
        {:error, :other_retryable_reason}
      ] do
  foo()
after
  _ -> :ok
else
  error -> error
end

So - for some subset of errors attempt the retry, while for others give up instantly.

Currently it is impossible:

  • rescue_only works only for exceptions (foo would need to raise instead of returning {:error, reason})
  • atoms is for, well... atoms, not tuples (although with this interesting exception (if the first element of 2–elements tuple is a given atom the retry will kick in)

I can't see clear way of this situation. Some ideas:

  • third option, tuples, which would match any tuples specified by the user (any length, not necessarily (:error, reason}
  • allowing rescue_only to accept all sort of things, mixed - exceptions, atoms, tuples

What are your thoughts on that?

@nathanalderson
Copy link
Contributor

nathanalderson commented Nov 21, 2022

What if it accepted a list of patterns? I would love this for Exceptions as well. I'm willing to try a PR in that direction if interested.

@rafal0p
Copy link
Author

rafal0p commented Nov 22, 2022

Could you give an example of such API?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants