Class: RankMirror::Speed

Inherits:
Object
  • Object
show all
Defined in:
lib/rankmirror/speed.rb

Instance Method Summary collapse

Constructor Details

#initialize(uri) ⇒ Speed

Returns a new instance of Speed.



5
6
7
# File 'lib/rankmirror/speed.rb', line 5

def initialize(uri)
	@uri = uri
end

Instance Method Details

#getObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/rankmirror/speed.rb', line 9

def get
	if RankMirror::Reachable.new(@uri,500).reachable?
		r = Curl::Easy.new(@uri)
		r.perform
		return r.download_speed / 1024.0
	else
		# usually in this case, the mirror is online but:
		# 1. has bad repodata. eg. not fully rsync the origin, or even empty. 
		# 2. volatile. sometimes at good speed, sometimes unreachable.
		# 3. too slow. takes more than 5 seconds to start a download.
		# not break here because we're about to find out the good mirrors, not the bad ones.
		return 0
	end
end