lib/zold/remotes.rb in zold-0.11.7 vs lib/zold/remotes.rb in zold-0.11.8
- old
+ new
@@ -32,10 +32,13 @@
# All remotes
class Remotes
# The default TCP port all nodes are supposed to use.
PORT = 4096
+ # At what amount of errors we delete the remote automatically
+ TOLERANCE = 50
+
# Empty, for standalone mode
class Empty
def all
[]
end
@@ -136,13 +139,22 @@
all.each do |r|
begin
yield Remotes::Remote.new(r[:host], r[:port], score, log: log)
rescue StandardError => e
error(r[:host], r[:port])
- log.info("#{Rainbow("#{r[:host]}:#{r[:port]}").red}: #{e.message}")
+ errors = errors(r[:host], r[:port])
+ log.info("#{Rainbow("#{r[:host]}:#{r[:port]}").red}: #{e.message}; errors=#{errors}")
log.debug(e.backtrace[0..5].join("\n\t"))
+ remove(r[:host], r[:port]) if errors > Remotes::TOLERANCE
end
end
+ end
+
+ def errors(host, port = Remotes::PORT)
+ raise 'Port has to be of type Integer' unless port.is_a?(Integer)
+ list = load
+ raise "#{host}:#{port} is absent among #{list.count} remotes" unless exists?(host, port)
+ list.find { |r| r[:host] == host.downcase && r[:port] == port }[:errors]
end
def error(host, port = Remotes::PORT)
raise 'Port has to be of type Integer' unless port.is_a?(Integer)
list = load