Class: Whacamole::Stream
- Inherits:
-
Object
- Object
- Whacamole::Stream
- Defined in:
- lib/whacamole/stream.rb
Instance Method Summary collapse
- #dispatch_handlers(chunk) ⇒ Object
-
#initialize(url, restart_handler, config_restart_threshold, &blk) ⇒ Stream
constructor
A new instance of Stream.
- #watch ⇒ Object
Constructor Details
#initialize(url, restart_handler, config_restart_threshold, &blk) ⇒ Stream
7 8 9 10 11 12 13 |
# File 'lib/whacamole/stream.rb', line 7 def initialize(url, restart_handler, config_restart_threshold, &blk) @url = url @restart_handler = restart_handler @dynos = restart_handler.dynos @event_handler = blk @restart_threshold = config_restart_threshold end |
Instance Method Details
#dispatch_handlers(chunk) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/whacamole/stream.rb', line 27 def dispatch_handlers(chunk) memory_size_from_chunk(chunk).each do |dyno, size| event = Events::DynoSize.new({:process => dyno, :size => size, :units => "MB"}) event_handler.call(event) restart(event.process) if restart_necessary?(event) end # TODO: handle R14 errors here also end |
#watch ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/whacamole/stream.rb', line 15 def watch uri = URI(url) Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http| request = Net::HTTP::Get.new(uri.request_uri) http.request(request) do |response| response.read_body do |chunk| dispatch_handlers(chunk) end end end end |