Skip to content

Conversation

@omarselim3008
Copy link

@omarselim3008 omarselim3008 commented Nov 26, 2021

Add :ignore option to retriable so that we can not retry exceptions that do not need one.

@omarselim3008 omarselim3008 changed the title Add ignore option to skip retrys Add ignore option to skip retries Nov 26, 2021
Copy link
Owner

@kamui kamui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, just some comments and also if you could add this to the readme docs.

ignore = local_config.ignore

exception_list = on.is_a?(Hash) ? on.keys : on
exception_list = on.is_a?(Hash) ? on.keys : [on].flatten
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you wrapping it in an array and flattening? Just in case on is a single Exception?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right yes. I was just making sure that this always returns an array, even if we pass a single object in the params.

lib/retriable.rb Outdated
return Timeout.timeout(timeout) { return yield(try) } if timeout
return yield(try)
rescue *[*exception_list] => exception
rescue *[*rescue_list] => exception
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we put on and ignore in an array and flatten it, do we still need this array splat expansion? This is here in case on is not an array, but you're with your changes on line 41-42, it's impossible now for this to not be an array.

end

if ignore.is_a?(Hash)
raise if ignore_list.any? do |e|
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What should happen if the user puts the same exception in both lists? In this implementation, ignore will override on right?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

end
end

if ignore.is_a?(Hash)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this ignore check happen before the on check? Isn't it generally better if we raise as soon as we can since it'll shortcut checking the other exceptions?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK can do that.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@omarselim3008
Copy link
Author

@kamui thanks for the review. Updated with your comments and also added the readme. Cheers.

@sshaw
Copy link

sshaw commented Nov 8, 2023

Nice feature to have!

@kamui kamui force-pushed the master branch 3 times, most recently from 6196a1e to c448885 Compare March 20, 2025 03:57
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

Successfully merging this pull request may close these issues.

3 participants