Skip to content

Allow to enable/disable Retriable globally#85

Open
fatkodima wants to merge 1 commit intokamui:masterfrom
fatkodima:allow-disabling
Open

Allow to enable/disable Retriable globally#85
fatkodima wants to merge 1 commit intokamui:masterfrom
fatkodima:allow-disabling

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.

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.

@kamui kamui force-pushed the master branch 3 times, most recently from 6196a1e to c448885 Compare March 20, 2025 03:57
@kamui kamui changed the title Allow to disable retriable blocks Allow to enable/disable Retriable globally Feb 18, 2026
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

Comments