diff options
author | André Arko <mail@arko.net> | 2015-04-24 02:44:25 -0400 |
---|---|---|
committer | André Arko <mail@arko.net> | 2015-04-24 02:44:25 -0400 |
commit | 9191d8ffe8f3dc242222f02a6db07e5ea766c524 (patch) | |
tree | 1d25d37889cff228a06c38c8cb0380e4a726e67c | |
parent | 5e6894ab97fb3257bbb1478b6d9dee09392c6a19 (diff) | |
parent | afbad470462b0878ea2cd2ee42cbec1121c288a5 (diff) | |
download | bundler-9191d8ffe8f3dc242222f02a6db07e5ea766c524.tar.gz |
Merge pull request #3586 from pducks32/configurable-timeout
Configurable timeout/retries/redirects
-rw-r--r-- | lib/bundler/cli.rb | 2 | ||||
-rw-r--r-- | lib/bundler/fetcher.rb | 6 | ||||
-rw-r--r-- | lib/bundler/retry.rb | 21 | ||||
-rw-r--r-- | lib/bundler/settings.rb | 14 | ||||
-rw-r--r-- | spec/bundler/retry_spec.rb | 11 | ||||
-rw-r--r-- | spec/bundler/settings_spec.rb | 15 |
6 files changed, 42 insertions, 27 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index 9b09946234..50133d2978 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -20,7 +20,7 @@ module Bundler current_cmd = args.last[:current_command].name custom_gemfile = options[:gemfile] || Bundler.settings[:gemfile] ENV['BUNDLE_GEMFILE'] = File.expand_path(custom_gemfile) if custom_gemfile - Bundler::Retry.attempts = options[:retry] || Bundler.settings[:retry] || Bundler::Retry::DEFAULT_ATTEMPTS + Bundler.settings[:retry] = options[:retry] if options[:retry] Bundler.rubygems.ui = UI::RGProxy.new(Bundler.ui) auto_install if AUTO_INSTALL_CMDS.include?(current_cmd) rescue UnknownArgumentError => e diff --git a/lib/bundler/fetcher.rb b/lib/bundler/fetcher.rb index b29e8dfb8a..42c6eb6717 100644 --- a/lib/bundler/fetcher.rb +++ b/lib/bundler/fetcher.rb @@ -58,9 +58,9 @@ module Bundler attr_accessor :disable_endpoint, :api_timeout, :redirect_limit, :max_retries end - self.redirect_limit = 5 # How many redirects to allow in one request - self.api_timeout = 10 # How long to wait for each API call - self.max_retries = 3 # How many retries for the API call + self.redirect_limit = Bundler.settings[:redirect] # How many redirects to allow in one request + self.api_timeout = Bundler.settings[:timeout] # How long to wait for each API call + self.max_retries = Bundler.settings[:retry] # How many retries for the API call def initialize(remote) @remote = remote diff --git a/lib/bundler/retry.rb b/lib/bundler/retry.rb index ea4d7577d9..585888f8e1 100644 --- a/lib/bundler/retry.rb +++ b/lib/bundler/retry.rb @@ -1,23 +1,24 @@ module Bundler # General purpose class for retrying code that may fail class Retry - DEFAULT_ATTEMPTS = 2 attr_accessor :name, :total_runs, :current_run class << self - attr_accessor :attempts + def default_attempts + default_retries + 1 + end + alias_method :attempts, :default_attempts + + def default_retries + Bundler.settings[:retry] + end end - def initialize(name, exceptions = nil, attempts = nil) + def initialize(name, exceptions = nil, retries = self.class.default_retries) @name = name - attempts ||= default_attempts + @retries = retries @exceptions = Array(exceptions) || [] - @total_runs = attempts.next # will run once, then upto attempts.times - end - - def default_attempts - return Integer(self.class.attempts) if self.class.attempts - DEFAULT_ATTEMPTS + @total_runs = @retries + 1 # will run once, then upto attempts.times end def attempt(&block) diff --git a/lib/bundler/settings.rb b/lib/bundler/settings.rb index 3d76671b65..181ff15498 100644 --- a/lib/bundler/settings.rb +++ b/lib/bundler/settings.rb @@ -3,6 +3,8 @@ require 'uri' module Bundler class Settings BOOL_KEYS = %w(frozen cache_all no_prune disable_local_branch_check gem.mit gem.coc).freeze + NUMBER_KEYS = %w(retry timeout redirect).freeze + DEFAULT_CONFIG = {:retry => 3, :timeout => 10, :redirect => 5} def initialize(root = nil) @root = root @@ -12,10 +14,13 @@ module Bundler def [](name) key = key_for(name) - value = (@local_config[key] || ENV[key] || @global_config[key]) + value = (@local_config[key] || ENV[key] || @global_config[key] || DEFAULT_CONFIG[name]) - if !value.nil? && is_bool(name) + case + when !value.nil? && is_bool(name) to_bool(value) + when !value.nil? && is_num(name) + value.to_i else value end @@ -84,6 +89,7 @@ module Bundler locations[:local] = @local_config[key] if @local_config.key?(key) locations[:env] = ENV[key] if ENV[key] locations[:global] = @global_config[key] if @global_config.key?(key) + locations[:default] = DEFAULT_CONFIG[key] if DEFAULT_CONFIG.key?(key) locations end @@ -169,6 +175,10 @@ module Bundler !(value.nil? || value == '' || value =~ /^(false|f|no|n|0)$/i || value == false) end + def is_num(value) + NUMBER_KEYS.include?(value.to_s) + end + def get_array(key) self[key] ? self[key].split(":").map { |w| w.to_sym } : [] end diff --git a/spec/bundler/retry_spec.rb b/spec/bundler/retry_spec.rb index 8e35a1013d..aa4e5e42ad 100644 --- a/spec/bundler/retry_spec.rb +++ b/spec/bundler/retry_spec.rb @@ -11,17 +11,6 @@ describe Bundler::Retry do expect(attempts).to eq(1) end - it "defaults to retrying twice" do - attempts = 0 - expect { - Bundler::Retry.new(nil).attempt do - attempts += 1 - raise "nope" - end - }.to raise_error("nope") - expect(attempts).to eq(3) - end - it "returns the first valid result" do jobs = [Proc.new{ raise "foo" }, Proc.new{ :bar }, Proc.new{ raise "foo" }] attempts = 0 diff --git a/spec/bundler/settings_spec.rb b/spec/bundler/settings_spec.rb index 1e197f22f0..e1dd61bead 100644 --- a/spec/bundler/settings_spec.rb +++ b/spec/bundler/settings_spec.rb @@ -15,6 +15,21 @@ describe Bundler::Settings do end end + describe "#[]" do + context "when not set" do + context "when default value present" do + it "retrieves value" do + expect(settings[:retry]).to be 3 + end + end + + it "returns nil" do + expect(settings[:buttermilk]).to be nil + end + end + end + + describe "#mirror_for" do let(:uri) { URI("https://rubygems.org/") } |