Sha256: 434ca9c6e86044f85f7d8dc6e312e7c1c3dea7c6991a027a5beb873f8426be0a
Contents?: true
Size: 1.32 KB
Versions: 17
Compression:
Stored size: 1.32 KB
Contents
class Repository < ActiveRecord::Base belongs_to :network six_guid attr_accessor :ping_value PING_PACKET_SIZE = 1372 def self.rank(pr = false) repos = self.find(:all) repos.each do |rep| puts "Processing #{rep.url}" if pr rep.ping_value = rep.ping! sleep 1 end repos.sort!{|a, b| a.ping_value <=> b.ping_value } repos.each_with_index do |rep,index| rep.priority = index rep.save end repos end def prio self.priority.nil? ? 9999 : self.priority end def ping! logger.info "Handling #{self.address}" out = %x[ping -n 10 -f -l #{PING_PACKET_SIZE} #{self.address}] vals = [] out.each_line do |l| l[/=([0-9]*)ms/] if $1 vals << $1.to_i end end logger.debug "Out: #{out}, Vals: #{vals}" bla = 0 vals.each {|v| bla += v } bla == 0 ? 9999 : bla / vals.size end def ping SixUpdaterWeb.run_program("ping", SixUpdaterWeb::BASE_PATH, "-f -l #{PING_PACKET_SIZE} -n 30 #{self.address}") end def tracert SixUpdaterWeb.run_program("tracert", SixUpdaterWeb::BASE_PATH, "-d #{self.address}") end def address self.url.sub("rsync://", "") end def to_label "#{self.url}" end def to_updater_yml self.url end end
Version data entries
17 entries across 17 versions & 1 rubygems