Class: Repository
Constant Summary
collapse
- PING_PACKET_SIZE =
1372
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#associated_valid?, #no_errors_in_associated?, #save_associated, #save_associated!, #save_with_unsaved_flag, #unsaved=, #unsaved?
Instance Attribute Details
#ping_value ⇒ Object
Returns the value of attribute ping_value.
5
6
7
|
# File 'lib/six-updater-web/app/models/repository.rb', line 5
def ping_value
@ping_value
end
|
Class Method Details
.rank(pr = false) ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/six-updater-web/app/models/repository.rb', line 9
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
|
Instance Method Details
52
53
54
|
# File 'lib/six-updater-web/app/models/repository.rb', line 52
def address
self.url.sub("rsync://", "")
end
|
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/six-updater-web/app/models/repository.rb', line 28
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
|
24
25
26
|
# File 'lib/six-updater-web/app/models/repository.rb', line 24
def prio
self.priority.nil? ? 9999 : self.priority
end
|
56
57
58
|
# File 'lib/six-updater-web/app/models/repository.rb', line 56
def to_label
"#{self.url}"
end
|
#to_updater_yml ⇒ Object
60
61
62
|
# File 'lib/six-updater-web/app/models/repository.rb', line 60
def to_updater_yml
self.url
end
|