-
Notifications
You must be signed in to change notification settings - Fork 21
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
Retry block change #3
Conversation
OK, rubocop is telling me annoying things like the method has too many lines! I am not sure how to make it pass rubocop without actually harming readability, but I'll first wait for feedback on the actual logic choices, before figuring out or asking for help on how to make rubocop happier. |
89ab0e6
to
69d1e8f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jrochkind don't worry about Rubocop stuff, this middleware needs good refactoring, but we can get to that later.
Feel free to update .rubocop_todo.yml so that the failing cops are passing 👍
The implementation and logic look good 🙌!
I tried extracting a separate method i'm not sure if that change improved or harmed the actual code more readability/maintainability though. So I guess I'll just add the existing ones to the .rubocop.todo, I'm not famiiar with that, so I'll have to figure out how it works. Otherwise, on the various questions I asked, @iMacTia , you're thinking things are fine how they are? Or just don't have energy to think about them? |
Tha file is auto-generated, you just run Apologies about the questions, today was Faraday 2.0 release day and I've been extra busy, will go through them now:
|
Thanks! Hm, I thought unrecognized options would raise. If unrecognized options are silent failures... yeah. I think that is not great, I think best contemporary ruby practice is to have unrecognized keyword args immediately raise an ArgumentError, because having typo or old args be silent failures is bad news generally. using actual ruby 2.0+ keyword arguments, you get ArgumentError on unrecognized kw arg automatically, I think the silent failure came from the "path of least resistance" back when "keyword arguments" were always just Hashes. But looking at the actual code here... which probably comes from pre-ruby 2.0 days too.... it's not obvious to me how to make that so, and it's probably an issue for Faraday in general. I guess maybe So okay, for another (maybe, probably not) day. And we'll leave the option name alone, it's fine even if not ideal! Thank you for your help! |
@iMacTia Note rubocop would add |
Gah, I might be using a different version of rubocop than CI, cause that thing has become an issue |
36d4288
to
ab7a74c
Compare
The above is all true for keyword arguments, but as you correctly pointed out we don't use those in the initialiser. Instead we use some old custom |
OK, it's green! Since I have you here I"m going to take the liberty of mentioning something else unrelated -- congrats on Faraday 2.0 release. In my communities people are trying to figure out how to make a gem that can work with faraday 1 OR 2 -- since the apps using our gems (that use faraday) may have other dependencies still stuck on faraday 1, we need to support faraday 1 or 2 for a while. Like... maybe Some of this might need to be figured out in practice, but since Faraday is so often used by gems ("intermediate dependencies"), it would probably be a useful addition to the upgrade guide if anyone can figure out good patterns for an intermediate dependency supporting both Faraday 1 and 2, at app's choice. |
Thanks for raising the point regarding upgrading to Faraday 2.0, I've had a few people reaching out already with similar comments. I'm currently thinking what's the best way to tackle this and could summarise them on a specific doc. If you could point me to where this is being discussed in open communities, it would provide me with valuable use-cases! |
Some discussion was on a slack, but here is some public discussion. It's a little bit confusing.
And here's a problem I noticed if your gem uses I wonder if you want to consider adding a faraday-retry dependency back to faraday for now, like you did with other extracted middleware. (I also wonder if default_adapter should have remained :net_http, but that ship has sailed). |
A potentially better solution would be to remove them from the codebase of Faraday 1.x as well, and add them back as external gem dependencies. This way you'd be able to add them to your gem as well and it would work fine with both Faraday 1.0 and 2.0 (the correct version would be loaded accordingly) |
Yes, that's an interesting idea. In Faraday 1.0 faraday-retry ( One trick would be that we have some intermediate gems who currently allow faraday down to But not sure what happens if you load the faraday-retry gem with an older existing faraday 1.0 that still has it's own retry middleware... So okay, another alternate option would be to make faraday-retry gem no-op if loaded with faraday 1.x. Make sure it avoids registering itself with faraday in that case, it just sits there as unused code. So an intermediate gem could express it as a dependency -- in faraday 1.0, it'll sit there as un-needed un-used code, but won't hurt anything. In faraday 2.0 where it's needed, it'll be there. All of this of course applies to |
That might be a bit hard to be fair. We're not actively maintaing Faraday 0.x so the required ruby version there would be hard to satisfy. Also, Faraday 1.0 is basically backwards-compatible with 0.x
I played with this locally a bit, and it seems fine if you have it on the gemfile, as far as you don't require it. |
retry_block takes keyword arguments instead of positional, which is much more manageable with so many args. (keyword args on lambda/proc objects have been supported since ruby 2.1)
There are some argument changes too:
will_retry_in
, for number of seconds until retry that event is forretries_remaining
toretry_count
, which counts up from 0. I think this is more likely to be what someone wants. (You can of course calculate the converse either way with options.max)Questions:
will_retry_in
the right name? Best i could come up with, but happy to change to whatever you prefer.retry_count
the right name? Same.retry_count
start at 0 or 1? I figured 0, in part because at the point retry_block is called, no retries have actually happened yet, it's called before the retry (and in fact before waiting the will_retry_in interval). This is existing behavior. But can change if you prefer 1.retry_block
even the right name for this? As long as we're doing backwards incompats, should it beretry_proc
or something instead? I didn't change it cause I have no strong feelings, but figured it was worth bringing up. Perhaps a name change would make bakwards compat even more obvious too.