Sha256: bb3cf415e1a52360f2671798db52d56ed993f315a24c3fb268e4cf1438b7c16b

Contents?: true

Size: 1.25 KB

Versions: 18

Compression:

Stored size: 1.25 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 < 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

    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

18 entries across 18 versions & 1 rubygems

Version Path
ring-sqa-0.4.3 lib/ring/sqa/poller/sender.rb
ring-sqa-0.4.2 lib/ring/sqa/poller/sender.rb
ring-sqa-0.4.1 lib/ring/sqa/poller/sender.rb
ring-sqa-0.3.1 lib/ring/sqa/poller/sender.rb
ring-sqa-0.3.0 lib/ring/sqa/poller/sender.rb
ring-sqa-0.2.2 lib/ring/sqa/poller/sender.rb
ring-sqa-0.2.1 lib/ring/sqa/poller/sender.rb
ring-sqa-0.2.0 lib/ring/sqa/poller/sender.rb
ring-sqa-0.1.12 lib/ring/sqa/poller/sender.rb
ring-sqa-0.1.11 lib/ring/sqa/poller/sender.rb
ring-sqa-0.1.10 lib/ring/sqa/poller/sender.rb
ring-sqa-0.1.9 lib/ring/sqa/poller/sender.rb
ring-sqa-0.1.8 lib/ring/sqa/poller/sender.rb
ring-sqa-0.1.7 lib/ring/sqa/poller/sender.rb
ring-sqa-0.1.6 lib/ring/sqa/poller/sender.rb
ring-sqa-0.1.5 lib/ring/sqa/poller/sender.rb
ring-sqa-0.1.4 lib/ring/sqa/poller/sender.rb
ring-sqa-0.1.3 lib/ring/sqa/poller/sender.rb