lib/zold/commands/remote.rb in zold-0.13.8 vs lib/zold/commands/remote.rb in zold-0.13.9
- old
+ new
@@ -147,25 +147,26 @@
end
# Returns an array of Zold::Score
def elect(opts)
scores = []
- @remotes.all.sample(1).each do |winner|
- @remotes.iterate(@log, farm: @farm) do |r|
- next if r.host != winner[:host] || r.port != winner[:port]
- res = r.http('/').get
- r.assert_code(200, res)
- score = Score.parse_json(JSON.parse(res.body)['score'])
- r.assert_valid_score(score)
- r.assert_score_ownership(score)
- r.assert_score_strength(score) unless opts['ignore-score-weakness']
- r.assert_score_value(score, Tax::EXACT_SCORE) unless opts['ignore-score-value']
- @log.info("Elected: #{score}")
- scores << score
- end
+ @remotes.iterate(@log, farm: @farm) do |r|
+ res = r.http('/').get
+ r.assert_code(200, res)
+ score = Score.parse_json(JSON.parse(res.body)['score'])
+ r.assert_valid_score(score)
+ r.assert_score_ownership(score)
+ r.assert_score_strength(score) unless opts['ignore-score-weakness']
+ r.assert_score_value(score, Tax::EXACT_SCORE) unless opts['ignore-score-value']
+ scores << score
end
- @log.info("No winners elected out of #{@remotes.all.count} remotes") if scores.empty?
+ scores = scores.sample(1)
+ if scores.empty?
+ @log.info("No winners elected out of #{@remotes.all.count} remotes")
+ else
+ @log.info("Elected: #{scores[0]}")
+ end
scores
end
def trim(opts)
@remotes.all.each do |r|
@@ -188,15 +189,14 @@
@remotes.rescore(score.host, score.port, score.value)
if Semantic::Version.new(VERSION) < Semantic::Version.new(json['version'])
if opts['reboot']
@log.info("#{r}: their version #{json['version']} is higher than mine #{VERSION}, reboot! \
(use --never-reboot to avoid this from happening)")
- Kernel.exit(0)
- else
- @log.info("#{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")
+ terminate
end
+ @log.info("#{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'])
end
@@ -212,8 +212,13 @@
if total.zero?
@log.debug("The list of remotes is #{Rainbow('empty').red}, run 'zold reset'!")
else
@log.debug("There are #{total} known remotes")
end
+ end
+
+ def terminate
+ @log.info("Threads: #{Thread.list.map { |t| "#{t.name}/#{t.status}" }.join(', ')}")
+ Kernel.exit(0)
end
end
end