class Ring::SQA::Sender

Constants

INTERVAL
INTER_NODE_GAP

Public Class Methods

new(database, nodes) click to toggle source
# File lib/ring/sqa/poller/sender.rb, line 30
def initialize database, nodes
  @db    = database
  @nodes = nodes
  run
end

Public Instance Methods

run() click to toggle source
# File lib/ring/sqa/poller/sender.rb, line 8
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 < 0
      Log.warn "Send loop duration was negative - ntp sync?"
    elsif duration < INTERVAL
      sleep INTERVAL-duration
    else
      Log.warn "Send loop took longer than #{INTERVAL}s"
    end
  end
  udp.close
end

Private Instance Methods

query(node, udp) click to toggle source
# File lib/ring/sqa/poller/sender.rb, line 36
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