lib/zold/commands/remote.rb in zold-0.14.23 vs lib/zold/commands/remote.rb in zold-0.14.24
- old
+ new
@@ -81,10 +81,13 @@
'Don\'t complain when their score is too small',
default: false
o.integer '--min-score',
"The minimum score required for winning the election (default: #{Tax::EXACT_SCORE})",
default: Tax::EXACT_SCORE
+ o.integer '--max-winners',
+ 'The maximum amount of election winners the election (default: 1)',
+ default: 1
o.bool '--force',
'Add/remove if if this operation is not possible',
default: false
o.bool '--skip-ping',
'Don\'t ping back the node when adding it (not recommended)',
@@ -195,15 +198,15 @@
r.assert_score_ownership(score)
r.assert_score_strength(score) unless opts['ignore-score-weakness']
r.assert_score_value(score, opts['min-score']) unless opts['ignore-score-value']
scores << score
end
- scores = scores.sample(1)
+ scores = scores.sample(opts['max-winners'])
if scores.empty?
@log.info("No winners elected out of #{@remotes.all.count} remotes")
else
- @log.info("Elected: #{scores[0]}")
+ scores.each { |s| @log.info("Elected: #{s}") }
end
scores
end
def trim(opts)
@@ -237,10 +240,10 @@
@log.debug("#{r}: their version #{json['version']} is higher than mine #{VERSION}, \
it's recommended to reboot, but I don't do it because of --never-reboot")
end
if deep
json['all'].each do |s|
- add(s['host'], s['port'], opts) unless @remotes.exists?(s['host'], s['port'])
+ @remotes.add(s['host'], s['port'])
end
end
capacity << { host: score.host, port: score.port, count: json['all'].count }
@log.info("#{r}: the score is #{Rainbow(score.value).green} (#{json['version']}) \
in #{(Time.now - start).round(2)}s")