Class: Kubeclient::Common::WatchStream
- Inherits:
-
Object
- Object
- Kubeclient::Common::WatchStream
- Defined in:
- lib/kubeclient/watch_stream.rb
Overview
HTTP Stream used to watch changes on entities
Instance Method Summary collapse
- #each ⇒ Object
- #finish ⇒ Object
-
#initialize(uri, options) ⇒ WatchStream
constructor
A new instance of WatchStream.
Constructor Details
#initialize(uri, options) ⇒ WatchStream
Returns a new instance of WatchStream.
7 8 9 10 11 |
# File 'lib/kubeclient/watch_stream.rb', line 7 def initialize(uri, ) @uri = uri @http = nil @options = .merge(read_timeout: nil) end |
Instance Method Details
#each ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/kubeclient/watch_stream.rb', line 13 def each @finished = false @http = Net::HTTP.start(@uri.host, @uri.port, @options) buffer = '' request = Net::HTTP::Get.new(@uri) @http.request(request) do |response| unless response.is_a? Net::HTTPSuccess fail KubeException.new(response.code, response.) end response.read_body do |chunk| buffer << chunk while (line = buffer.slice!(/.+\n/)) yield WatchNotice.new(JSON.parse(line)) end end end rescue Errno::EBADF raise unless @finished end |
#finish ⇒ Object
35 36 37 38 |
# File 'lib/kubeclient/watch_stream.rb', line 35 def finish @finished = true @http.finish if !@http.nil? && @http.started? end |