Class: GoogleWebTranslate::ServerList
- Inherits:
-
Object
- Object
- GoogleWebTranslate::ServerList
- Defined in:
- lib/google_web_translate/server_list.rb
Class Method Summary collapse
Class Method Details
.next_server(rate_limit = nil) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/google_web_translate/server_list.rb', line 14 def next_server(rate_limit = nil) @mutex ||= Mutex.new @mutex.synchronize do @counter ||= 0 @counter += 1 list = servers.sort_by { |i| i.counter || 0 } server = list[0] server.counter = @counter sleep(rate_limit_delay(server, rate_limit)) server.last_used_at = Time.now server end end |
.servers ⇒ Object
9 10 11 12 |
# File 'lib/google_web_translate/server_list.rb', line 9 def servers update_servers if @servers.nil? @servers.dup end |