Comments (5)
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.
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.
You could also just override the retriable config in your spec_helper
this is the preferred approach where i'm from
from retriable.
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.
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)
- Dependabot can't resolve your Ruby dependency files
- Dependabot can't resolve your Ruby dependency files
- Question: Short Circuiting Retriable While Testing Your App HOT 1
- Error message on max_elapsed_time HOT 2
- rubinius travis failures seem to be due to srand(0) not seeding random the same way HOT 1
- the rubygems summary still has really bad grammar HOT 1
- Have a parameter to supply a proc that is only called on the final failure
- Travis Build fails when installing rubygems-update
- Callback if max elapsed time has been reached
- Using RUBY_VERSION in a gemspec doesn't work HOT 2
- Feature request: allow `with_context` without context configuration HOT 3
- Replace houndci HOT 3
- sleep_disabled option not documented HOT 2
- cannot load such file -- retriable HOT 1
- Should the `on` argument to `with_context` be additive? HOT 1
- Retriable only trying for 20 times even though my tries is 360. Not sure why that's happpening. HOT 3
- Request: Remove Gemfile.lock from .gitignore HOT 8
- Timeout::timeout is inherently unsafe HOT 2
- CI: bundler 1.17.3 seems not to work w/ ruby-head
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from retriable.