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

Would it make sense to make retry transient? function public? #371

Open
jozuas opened this issue Jun 11, 2024 · 4 comments
Open

Would it make sense to make retry transient? function public? #371

jozuas opened this issue Jun 11, 2024 · 4 comments

Comments

@jozuas
Copy link
Contributor

jozuas commented Jun 11, 2024

I'm thinking that it would be nice to have the ability to define your own retry function, and in the retry function if the conditions that I care about don't match, default to

defp transient?(%Req.Response{status: status}) when status in [408, 429, 500, 502, 503, 504] do

I'll be happy to make a PR if this sounds reasonable.

@jozuas jozuas changed the title Would it make sense to make default retry functions public? Would it make sense to make retry transient? function public? Jun 11, 2024
@wojtekmach
Copy link
Owner

wojtekmach commented Jun 11, 2024

This is very arbitrary but I'd like to keep Req.Steps to just have steps functions as it's already pretty big module. The downside is we can't have this function which I agree would be very convenient to have. Perhaps there is another way to solve this?

@jozuas
Copy link
Contributor Author

jozuas commented Jun 11, 2024

I had a look at Req.Steps to see if there's a more general pattern that we could take advantage of, but sadly it seems that only the transient? function would benefit from being exposed. Creating a whole new module e.g. Req.Conveniences would not look so great if there's only one function there of interest.

The retry function implementation can return a tuple {:delay, milliseconds}, maybe we could support new options {:retry, :transient} and {:retry, :safe_transient}?

    Req.new(
      ...,
      retry: fn
        _req, %Req.Response{status: 403} ->
          # Hypothetical service that returns HTTP 403 instead of 429 for "Too Many Requests" 
          {:delay, 30_000}

        _req, _resp ->
          {:retry, :safe_transient}
      end
    )

@jozuas
Copy link
Contributor Author

jozuas commented Jun 20, 2024

@wojtekmach how does the proposal sound? Is this something I could start working on that the Req library would be happy to accept?

@wojtekmach
Copy link
Owner

Sorry I'm still considering it.

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