lib/zold/remotes.rb in zold-0.23.6 vs lib/zold/remotes.rb in zold-0.23.7
- old
+ new
@@ -43,21 +43,25 @@
# One remote.
class RemoteNode
# When something is wrong with the assertion
class CantAssert < StandardError; end
+ attr_reader :touched
+
def initialize(host:, port:, score:, idx:, master:, network: 'test', log: Log::NULL)
@host = host
@port = port
@score = score
@idx = idx
@master = master
@network = network
@log = log
+ @touched = false
end
def http(path = '/')
+ @touched = true
Http.new(uri: "http://#{@host}:#{@port}#{path}", score: @score, network: @network)
end
def master?
@master
@@ -65,10 +69,14 @@
def to_s
"#{@host}:#{@port}/#{@idx}"
end
+ def to_mnemo
+ "#{@host}:#{@port}"
+ end
+
def assert_code(code, response)
msg = response.status_line.strip
return if response.status.to_i == code
if response.headers && response.headers['X-Zold-Error']
raise CantAssert, "Error ##{response.status} \"#{response.headers['X-Zold-Error']}\"
@@ -191,24 +199,25 @@
raise 'Farm can\'t be nil' if farm.nil?
Hands.exec(Concurrent.processor_count * 4, all) do |r, idx|
Thread.current.name = "remotes-#{idx}@#{r[:host]}:#{r[:port]}"
start = Time.now
best = farm.best[0]
+ node = RemoteNode.new(
+ host: r[:host],
+ port: r[:port],
+ score: best.nil? ? Score::ZERO : best,
+ idx: idx,
+ master: master?(r[:host], r[:port]),
+ log: log,
+ network: @network
+ )
begin
- yield RemoteNode.new(
- host: r[:host],
- port: r[:port],
- score: best.nil? ? Score::ZERO : best,
- idx: idx,
- master: master?(r[:host], r[:port]),
- log: log,
- network: @network
- )
+ yield node
raise 'Took too long to execute' if (Time.now - start).round > @timeout
- unerror(r[:host], r[:port])
+ unerror(r[:host], r[:port]) if node.touched
rescue StandardError => e
error(r[:host], r[:port])
- log.info("#{Rainbow("#{r[:host]}:#{r[:port]}").red}: #{e.message} in #{Age.new(start)}")
+ log.info("#{Rainbow(node).red}: #{e.message} in #{Age.new(start)}")
log.debug(Backtrace.new(e).to_s)
remove(r[:host], r[:port]) if r[:errors] > TOLERANCE
end
end
end