Git Product home page Git Product logo

Comments (5)

apurvis avatar apurvis commented on August 22, 2024 1

Hmm... the "global" value doesn't seem to override the contexts.

right; this is on purpose. everything you say here makes sense to me about how to deal with this issue (especially when you are using the new contexts feature). i don't think i could come up with a better answer, and a few lines of code in spec_helper.rb sounds pretty reasonable to me. spec_helper.rb is not generally where the most elegant code lives in a project lol.

i guess it might be slightly smoother if :global was also a real context that set the defaults - in which case you would only need the

Retriable.configure do |c|
  c.contexts.keys.each do |context|
    c.contexts[context][:tries]         = 2
    c.contexts[context][:base_interval] = 0
  end
end

part... but that also seems a bit like overkill to avoid a few lines in spec_helper.rb

from retriable.

kamui avatar kamui commented on August 22, 2024

What kind of tests are you writing? Are you testing that code is retried or that some exception is caught? Because, otherwise it shouldn't slow things down if no exception is occurring right?

Otherwise, your approach is probably fine. You could also just override the retriable config in your spec_helper instead or you could check the environment inside the configure block:

Retriable.configure do |c|
  if Rails.env.test?
    c.tries = 1
  end
end

from retriable.

apurvis avatar apurvis commented on August 22, 2024

You could also just override the retriable config in your spec_helper

this is the preferred approach where i'm from

from retriable.

jeremywadsack avatar jeremywadsack commented on August 22, 2024

You could also just override the retriable config in your spec_helper

Hmm... the "global" value doesn't seem to override the contexts.

So, for example, I have this in my config/initializers/retriable.rb:

Retriable.configure do |c|
  c.contexts[:google_api] = {
      tries:         Settings.google_api.retry_limit,
      base_interval: Settings.google_api.retry_sleep,
      on:            [
          Faraday::SSLError,
          Faraday::ConnectionFailed,
          Faraday::TimeoutError,
          Net::ReadTimeout,
          Signet::AuthorizationError,
          Errno::ECONNRESET,
          OpenSSL::SSL::SSLError
      ]
  }
end

And when I set this in spec/spec_helper.rb it doesn't change the exponential backoff for the tests in that context:

Retriable.configure do |c|
  c.multiplier    = 1.0
  c.rand_factor   = 0.0
  c.base_interval = 0
end

I have to explicitly override each of the contexts' values:

Retriable.configure do |c|
  c.multiplier    = 1.0
  c.rand_factor   = 0.0
  c.base_interval = 0

  c.contexts[:google_api][:tries]         = 2
  c.contexts[:google_api][:base_interval] = 0
end

That makes sense in general — I would expect explicit context's values to override the general one, but that makes it complicated to set the tries and base for all contexts. In the end I came up with this:

Retriable.configure do |c|
  c.multiplier    = 1.0
  c.rand_factor   = 0.0
  c.base_interval = 0

  c.contexts.keys.each do |context|
    c.contexts[context][:tries]         = 2
    c.contexts[context][:base_interval] = 0
  end
end

Might there be a better way to address this?

from retriable.

apurvis avatar apurvis commented on August 22, 2024

given that this question seems to have come up a few times, i would support a README pull request to explain how to handle it.

from retriable.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.