-
Notifications
You must be signed in to change notification settings - Fork 46
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
Accept Proc in the :on
argument
#55
base: master
Are you sure you want to change the base?
Conversation
spec/retriable_spec.rb
Outdated
end | ||
|
||
it '#retriable does not retry with a hash exception where the value is a proc that returns false' do | ||
matcher = ->(e, *args) { e.message == 'something went wrong' } |
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.
Unused block argument - args. If it's necessary, use _ or _args as an argument name to indicate that it won't be used.
spec/retriable_spec.rb
Outdated
expect(tries).must_equal 2 | ||
end | ||
|
||
it '#retriable does not retry with a hash exception where the value is a proc that returns false' do |
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.
Line is too long. [104/80]
spec/retriable_spec.rb
Outdated
@@ -313,6 +313,34 @@ class SecondTestError < TestError; end | |||
expect(exceptions[3].class).must_equal StandardError | |||
end | |||
|
|||
it '#retriable retries with a hash exception where the value is a proc that returns true' do | |||
matcher = ->(e, _try, _elapsed_time, _next_interval) { |
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.
Use the lambda method for multiline lambdas.
spec/retriable_spec.rb
Outdated
@@ -313,6 +313,34 @@ class SecondTestError < TestError; end | |||
expect(exceptions[3].class).must_equal StandardError | |||
end | |||
|
|||
it '#retriable retries with a hash exception where the value is a proc that returns true' do |
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.
Line is too long. [96/80]
lib/retriable.rb
Outdated
on_retry.call(exception, try, elapsed_time.call, interval) if on_retry | ||
raise if try >= tries || (elapsed_time.call + interval) > max_elapsed_time | ||
sleep interval if sleep_disabled != true | ||
end | ||
end | ||
end | ||
|
||
def matched_exception?(on, exception, *additional_args) |
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.
Method has too many lines. [14/10]
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.
trivial but maybe rename additional_args
to proc_args
? so it's explicit in the naming where these args are going.
i don't love the name proc_args
so maybe you can think of something better (matcher_proc_args
?), but additional_args
kind of makes it seem like the args will be used in the matched_exception?
method, which they will not.
interval = intervals[index] | ||
raise unless matched_exception?(on, exception, try, elapsed_time.call, interval) |
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.
Line is too long. [88/80]
772867a
to
26ab1bf
Compare
@kamui ready! |
Ping! |
|
||
A `Regexp` (or array of `Regexp`s). If any of the `Regexp`s match the exception's message, the block will be retried. | ||
A `Proc` (or array of `Proc`s) that evaluates the exception being handled and returns `true` if the block should be retried. If any of the procs in the list return `true`, the block will be retried. | ||
You can also mix and match `Proc`s and `Regexp`s in an `Array` |
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.
this is all sort of duplicative of the docs above... it's probably better to just link back there than to duplicate the explanation.
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.
I'm just staying consistent with the style of this documentation. Above there are other expanded versions of what's on those bullet points as well.
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.
not sure how much water my opinion carries but in general i think this is a good change.
(you could propose the version bump to 3.2.0 on this PR though maybe @kamui just prefers to handle the version bumping himself) |
README.md
Outdated
- A single `Regexp` pattern (retries exceptions ONLY if their `message` matches the pattern) | ||
- An array of patterns (retries exceptions ONLY if their `message` matches at least one of the patterns) | ||
- An array of `Proc` and/or `Regexp` (retries exceptions ONLY if at least one exception matches `Regexp` or the `Proc` evaluates to `true`) |
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.
grammar: "retries exceptions ONLY if at least one exception message matches a Regexp
or at least one Proc
evaluates to true
" (or "returns truthy
"... not sure which it is but you should be correct and consistent in the documentation).
@kamui @rafaelsales what do we need to do here to get this merged? How can I help? |
Ping ^ |
lib/retriable.rb
Outdated
on_retry.call(exception, try, elapsed_time.call, interval) if on_retry | ||
raise if try >= tries || (elapsed_time.call + interval) > max_elapsed_time | ||
sleep interval if sleep_disabled != true | ||
end | ||
end | ||
end | ||
|
||
def matched_exception?(on, exception, *additional_args) |
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.
Naming/UncommunicativeMethodParamName: Method parameter must be at least 3 characters long.
@kamui could you take a look at this one? |
it "#retriable does not retry with a hash exception where the value is a proc that returns false" do | ||
matcher = ->(e, *_args) { e.message == "something went wrong" } | ||
tries = 0 | ||
expect { |
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.
Style/BlockDelimiters: Avoid using {...} for multi-line blocks.
e.message == "something went wrong" | ||
end | ||
tries = 0 | ||
expect { |
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.
Style/BlockDelimiters: Avoid using {...} for multi-line blocks.
Thank you so much @rafaelsales! Um abraço amigo de Portugal 🙌 . |
I hope this feature will be merged. |
#18