lib/zold/commands/push.rb in zold-0.11.3 vs lib/zold/commands/push.rb in zold-0.11.4
- old
+ new
@@ -42,10 +42,13 @@
def run(args = [])
opts = Slop.parse(args, help: true, suppress_errors: true) do |o|
o.banner = "Usage: zold push [ID...] [options]
Available options:"
+ o.array '--ignore-node',
+ 'Ignore this node and don\'t push to it',
+ default: []
o.bool '--sync',
'Wait until the server confirms merge and pushes all wallets further (default: false)',
default: false
o.bool '--help', 'Print instructions'
end
@@ -61,25 +64,33 @@
private
def push(wallet, opts)
total = 0
@remotes.iterate(@log) do |r|
- start = Time.now
- response = r.http(
- "/wallet/#{wallet.id}#{opts['sync'] ? '?sync=true' : ''}"
- ).put(File.read(wallet.path))
- if response.code == '304'
- @log.info("#{r}: same version of #{wallet.id} there")
- next
- end
- r.assert_code(200, response)
- json = JSON.parse(response.body)['score']
- score = Score.parse_json(json)
- r.assert_valid_score(score)
- raise "Score is too weak #{score}" if score.strength < Score::STRENGTH
- @log.info("#{r} accepted #{wallet.id} in #{(Time.now - start).round(2)}s: #{Rainbow(score.value).green}")
- total += score.value
+ total += push_one(wallet, r, opts)
end
@log.info("Total score for #{wallet.id} is #{total}")
+ end
+
+ def push_one(wallet, r, opts)
+ if opts['ignore-node'].include?(r.to_s)
+ @log.info("#{r} ignored because of --ignore-node")
+ return 0
+ end
+ start = Time.now
+ response = r.http(
+ "/wallet/#{wallet.id}#{opts['sync'] ? '?sync=true' : ''}"
+ ).put(File.read(wallet.path))
+ if response.code == '304'
+ @log.info("#{r}: same version of #{wallet.id} there")
+ return 0
+ end
+ r.assert_code(200, response)
+ json = JSON.parse(response.body)['score']
+ score = Score.parse_json(json)
+ r.assert_valid_score(score)
+ raise "Score is too weak #{score}" if score.strength < Score::STRENGTH
+ @log.info("#{r} accepted #{wallet.id} in #{(Time.now - start).round(2)}s: #{Rainbow(score.value).green}")
+ score.value
end
end
end