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

Add Request.WithRetryFunc #435

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

rafiramadhana
Copy link
Contributor

Resolves #427

@coveralls
Copy link
Collaborator

coveralls commented Oct 27, 2023

Coverage Status

coverage: 94.814% (+0.001%) from 94.813%
when pulling 539b74e on rafiramadhana:427-with-retry-fn
into 85c3b02 on gavv:master.

@gavv
Copy link
Owner

gavv commented Nov 9, 2023

Thanks for PR!

A few comments:

  1. I think WithRetryFunc should override built-in retry policy entirely. i.e., if retryFn is set, it should be used instead of shouldRetry(). Rationale:

    • otherwise, the user won't be able to cancel behavior of built-in policies if it's not desired
    • also it's not obvious how exactly combined built-in policy + custom retry func behave together (currently code uses logical AND but you can't just guess it, you need to checks docs or source code)
  2. After doing this, tests should be updated accordingly I guess.

  3. I suggest to rename "WithRetryFunc" to "WithRetryPolicyFunc" and in docs, say that "WithRetryPolicy" is for using one of built-in policies, and "WithRetryPolicyFunc" is for using custom user-defined policy. This way relations of these methods will be more clear.

  4. Let's also move WithRetryPolicyFunc right after WithRetryPolicy in the file.

  5. Let's make "WithRetryPolicy" and "WithRetryPolicyFunc" mutual exclusive. If user calls both, we'll report a failure. (Please cover it in TestRequest_Conflicts).

  6. Could you please also cover invalid usage of WithRetryPolicyFunc in TestRequest_Usage (move nil argument test there) and TestRequest_Order (add new test there)?

  7. Let's make examples in readme and comment a bit more illustrative, e.g. it can be return resp.StatusCode == http.StatusTeapot instead of return true.

@gavv gavv added the needs revision Pull request should be revised by its author label Nov 9, 2023
@rafiramadhana
Copy link
Contributor Author

I suggest to rename "WithRetryFunc" to "WithRetryPolicyFunc" and in docs, say that "WithRetryPolicy" is for using one of built-in policies, and "WithRetryPolicyFunc" is for using custom user-defined policy. This way relations of these methods will be more clear.

Let's make "WithRetryPolicy" and "WithRetryPolicyFunc" mutual exclusive.

overall, im agree with your concerns and suggestions

ok, i will do the update, thanks

@rafiramadhana
Copy link
Contributor Author

rafiramadhana commented Nov 13, 2023

@gavv updated, ready to review

@gavv gavv added ready for review Pull request can be reviewed and removed needs revision Pull request should be revised by its author labels Nov 16, 2023
@acouvreur
Copy link

Any news on this ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready for review Pull request can be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add WithRetryHandler for a custom RetryPolicy
4 participants