Sha256: e7bfb4f4b5420731d6c9b0518dbbbc1d5a9815fa0d2064e7cd07f5a508fbea27
Contents?: true
Size: 1.16 KB
Versions: 7
Compression:
Stored size: 1.16 KB
Contents
module Ring class SQA class Sender < Poller INTERVAL = 30 # duration pinging all nodes should take INTER_NODE_GAP = 0.01 # delay to sleep between each node def run udp = udp_socket loop do loop_start = Time.now @nodes.all.each do |node, _| query node, udp sleep INTER_NODE_GAP end duration = Time.now-loop_start if duration < INTERVAL sleep INTERVAL-duration else Log.warn "Send loop took longer than #{INTERVAL}s" end end udp.close end private def initialize database, nodes @db = database @nodes = nodes run end def query node, udp Log.debug "Sending query to #{node}" if CFG.debug? record = @db.add peer: node msg = [Time.now.utc.to_f.to_s, record.id].join ' ' udp.send msg, 0, node, port rescue Errno::ECONNREFUSED Log.warn "connection refused to '#{node}'" @db.update record.id, 'connection refused' rescue Errno::ENETUNREACH Log.warn "network unreachable to '#{node}'" @db.update record.id, 'network unreachable' end end end end
Version data entries
7 entries across 7 versions & 1 rubygems