lib/zold/commands/fetch.rb in zold-0.16.30 vs lib/zold/commands/fetch.rb in zold-0.17.0
- old
+ new
@@ -26,10 +26,12 @@
require 'tempfile'
require 'slop'
require 'rainbow'
require 'concurrent/atomics'
require 'zold/score'
+require 'concurrent'
+require 'parallel'
require_relative 'thread_badge'
require_relative 'args'
require_relative '../log'
require_relative '../age'
require_relative '../http'
@@ -67,14 +69,18 @@
'Don\'t fail if the wallet is absent in all remote nodes',
default: false
o.string '--network',
'The name of the network we work in',
default: 'test'
+ o.integer '--threads',
+ "How many threads to use for fetching wallets (default: #{[Concurrent.processor_count / 2, 2].max})",
+ default: [Concurrent.processor_count / 2, 2].max
o.bool '--help', 'Print instructions'
end
mine = Args.new(opts, @log).take || return
- (mine.empty? ? @wallets.all : mine.map { |i| Id.new(i) }).each do |id|
+ Parallel.map((mine.empty? ? @wallets.all : mine.map { |i| Id.new(i) }), in_threads: opts[:threads]) do |id|
fetch(id, Copies.new(File.join(@copies, id)), opts)
+ @log.debug("Worker: #{Parallel.worker_number} has fetched wallet #{id}")
end
end
private