-
Notifications
You must be signed in to change notification settings - Fork 0
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
Expand retry options #5
Conversation
@@ -56,12 +55,20 @@ def self.retry_action(opts = {}, &block) | |||
result = yield block | |||
return result | |||
rescue => e | |||
class_reraise = opts[:retry_error_classes] && !opts[:retry_error_classes].include?(e.class) | |||
retry_error_classes = opts[:retry_error_classes] |
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 went with determination of retry instead of determination of reraise... seems a little more straightforward?
oh also importantly, now you can pass an array of retry_error_messages instead of just a single string/regex. |
class_retry = retry_error_classes && retry_error_classes.include?(e.class) | ||
if class_retry && retry_error_messages && !retry_error_messages.any? { |m| e.message[m] } | ||
class_retry = false | ||
end |
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 find this confusing -- maybe this more straightfoward?
class_retry = retry_error_classes && retry_error_classes.include?(e.class)
message_retry = retry_error_messages && !retry_error_messages.any? { |m| e.message[m] }
retry = message_retry && class_retry
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.
that doesn't quite cut it unfortunately but yeah i agree it feels too
confusing.
if there ARE NOT provided retry_error_classes, a retry_error_messages entry
would be sufficient to cause a retry on its own.
if there ARE provided retry_error_classes AND retry_error_messages, both
the class and the message should match to retry (this is how a lot of our
retries are in the DW/now phorklift)
On Wed, Apr 1, 2015 at 12:20 PM, dollschasingmen [email protected]
wrote:
In lib/pester.rb
#5 (comment):@@ -56,12 +55,20 @@ def self.retry_action(opts = {}, &block)
result = yield block
return result
rescue => e
class_reraise = opts[:retry_error_classes] && !opts[:retry_error_classes].include?(e.class)
retry_error_classes = opts[:retry_error_classes]
retry_error_messages = opts[:retry_error_messages]
class_retry = retry_error_classes && retry_error_classes.include?(e.class)
if class_retry && retry_error_messages && !retry_error_messages.any? { |m| e.message[m] }
class_retry = false
end
i find this confusing -- maybe this more straightfoward?
class_retry = retry_error_classes && retry_error_classes.include?(e.class)
message_retry = retry_error_messages && !retry_error_messages.any? { |m|
e.message[m] }
retry = message_retry && class_retry—
Reply to this email directly or view it on GitHub
https://github.com/lumoslabs/pester/pull/5/files#r27602011.
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.
jaisus
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.
if retry_error_classes && !retry_error_messages
retry = retry_error_classes.include?(e.class)
elsif retry_error_messages && !retry_error_classes
retry = retry_error_messages.any? { |m| e.message[m] }
elsif retry_error_messages && retry_error_classes
retry = retry_error_messages.any? { |m| e.message[m] } && retry_error_classes.include?(e.class)
else
retry = false
end
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.
yeah that's clearer; i'll change it.
retry_decision = false | ||
else | ||
retry_decision = true | ||
end |
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.
Can we just bust the decision-making code into a different method with its own specs? This would get around the ABC rubocop warning I've been ignoring, because I haven't had a chance to actually, substantively refactor the code to just return a boolean.
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.
sure
On Wed, Apr 1, 2015 at 1:17 PM, Marc Bollinger [email protected]
wrote:
In lib/pester.rb
#5 (comment):
retry_error_messages = opts[:retry_error_messages]
reraise_error_classes = opts[:reraise_error_classes]
if retry_error_classes
if retry_error_messages
retry_decision = retry_error_classes.include?(e.class) && retry_error_messages.any? { |m| e.message[m] }
else
retry_decision = retry_error_classes.include?(e.class)
end
elsif retry_error_messages
retry_decision = retry_error_messages.any? { |m| e.message[m] }
elsif reraise_error_classes && reraise_error_classes.include?(e.class)
retry_decision = false
else
retry_decision = true
end
Can we just bust the decision-making code into a different method with its
own specs? This would get around the ABC rubocop warning I've been
ignoring, because I haven't had a chance to actually, substantively
refactor the code to just return a boolean.—
Reply to this email directly or view it on GitHub
https://github.com/lumoslabs/pester/pull/5/files#r27607050.
ok i'll go with unless |
k i put the proc stuff on a separate PR #6 |
match_type = class_reraise ? 'class' : 'message' | ||
opts[:logger].warn("Reraising exception from inside retry_action because provided #{match_type} was not matched.") | ||
unless should_retry?(e, opts) | ||
opts[:logger].warn("Reraising exception from inside retry_action.") | ||
raise | ||
end |
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.
yeah, this reads much more nicely. replace those "
s with '
? that warning is still on in rubocop
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.
oops sorry hang on
On Wed, Apr 1, 2015 at 2:48 PM, Marc Bollinger [email protected]
wrote:
In lib/pester.rb
#5 (comment):rescue => e
class_reraise = opts[:retry_error_classes] && !opts[:retry_error_classes].include?(e.class)
reraise_error = opts[:reraise_error_classes] && opts[:reraise_error_classes].include?(e.class)
- message_reraise = opts[:message] && !e.message[opts[:message]]
if class_reraise || message_reraise || reraise_error
match_type = class_reraise ? 'class' : 'message'
opts[:logger].warn("Reraising exception from inside retry_action because provided #{match_type} was not matched.")
unless should_retry?(e, opts)
opts[:logger].warn("Reraising exception from inside retry_action.") raise end
yeah, this reads much more nicely. replace those "s with '? that warning
is still on in rubocop—
Reply to this email directly or view it on GitHub
https://github.com/lumoslabs/pester/pull/5/files#r27615408.
…is dumb single quote preference altogether.
Better specs for on_max_attempts_exceeded proc
@slpsys i am noticing that pester doesn't exactly match our use case for all the stuff currently retried in phorklift / DW - the main difference is that a lot of the retries want a match both on the class of the error AND on the message fragment