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

Allow to disable retriable blocks #85

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fatkodima
Copy link
Contributor

This is primarily for testing convenience, but can be very useful in development, for example, when you want to quickly disable/reenable retrying.

@@ -222,6 +222,17 @@ def increment_tries_with_exception(exception_class = nil)
it "raises ArgumentError on invalid options" do
expect { described_class.retriable(does_not_exist: 123) { increment_tries } }.to raise_error(ArgumentError)
end

it "raises without retries when disabled" do
begin
Copy link

Choose a reason for hiding this comment

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

Style/RedundantBegin: Redundant begin block detected.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is needed because ruby < 2.5 requires explicit begin...ensure inside blocks.

@kamui
Copy link
Owner

kamui commented Jul 29, 2021

You could just do:

# config/initializers/retriable.rb
Retriable.configure do |c|
  if Rails.env.development?
    c.tries = 1
  end
end

Right?

@fatkodima
Copy link
Contributor Author

Yes, for simple cases.

I honestly do not remember, which specific example I had in mind. But from README changes you can see, how it also simplifies working with contexts. Sure, you can write something like this for each context:

Retriable.configure do |c|
   c.contexts[:google_api] = {
       tries:         Rails.env.test? ? 1 : 5,
       base_interval: 3,
       on:            [
           Net::ReadTimeout,
           Signet::AuthorizationError,
           Errno::ECONNRESET,
           OpenSSL::SSL::SSLError
       ]
   }
 end

But the proposed solution looks cleaner for me.

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.

2 participants