summaryrefslogtreecommitdiff
path: root/lib/bundler/compact_index_client.rb
diff options
context:
space:
mode:
authorDavid Rodríguez <deivid.rodriguez@riseup.net>2018-10-03 20:39:00 -0300
committerDavid Rodríguez <deivid.rodriguez@riseup.net>2019-03-08 13:31:05 +0100
commited85fb9f7acc20c317737f3e157bcee38fbd527c (patch)
treee9e682af316949ec1d3ae3862fa29a6463dd0a66 /lib/bundler/compact_index_client.rb
parentdcd5d2fc29cb08b771cd445f4b2089b7e2462652 (diff)
downloadbundler-ed85fb9f7acc20c317737f3e157bcee38fbd527c.tar.gz
Fallback to sequentially fetching specs on 429s
If the compact index returns TooManyRequests, take it easier by requesting dependencies sequentially instead.
Diffstat (limited to 'lib/bundler/compact_index_client.rb')
-rw-r--r--lib/bundler/compact_index_client.rb30
1 files changed, 23 insertions, 7 deletions
diff --git a/lib/bundler/compact_index_client.rb b/lib/bundler/compact_index_client.rb
index 6c241ca07a..2f713041c8 100644
--- a/lib/bundler/compact_index_client.rb
+++ b/lib/bundler/compact_index_client.rb
@@ -18,11 +18,6 @@ module Bundler
attr_reader :directory
- # @return [Lambda] A lambda that takes an array of inputs and a block, and
- # maps the inputs with the block in parallel.
- #
- attr_accessor :in_parallel
-
def initialize(directory, fetcher)
@directory = Pathname.new(directory)
@updater = Updater.new(fetcher)
@@ -31,7 +26,28 @@ module Bundler
@info_checksums_by_name = {}
@parsed_checksums = false
@mutex = Mutex.new
- @in_parallel = lambda do |inputs, &blk|
+ end
+
+ def execution_mode=(block)
+ Bundler::CompactIndexClient.debug { "execution_mode=" }
+ @endpoints = Set.new
+
+ @execution_mode = block
+ end
+
+ # @return [Lambda] A lambda that takes an array of inputs and a block, and
+ # maps the inputs with the block in parallel.
+ #
+ def execution_mode
+ @execution_mode || sequentially
+ end
+
+ def sequential_execution_mode!
+ self.execution_mode = sequentially
+ end
+
+ def sequentially
+ @sequentially ||= lambda do |inputs, &blk|
inputs.map(&blk)
end
end
@@ -51,7 +67,7 @@ module Bundler
def dependencies(names)
Bundler::CompactIndexClient.debug { "dependencies(#{names})" }
- in_parallel.call(names) do |name|
+ execution_mode.call(names) do |name|
update_info(name)
@cache.dependencies(name).map {|d| d.unshift(name) }
end.flatten(1)