class Etcdv3::Namespace::Watch
Public Class Methods
new(hostname, credentials, timeout, namespace, metadata = {})
click to toggle source
# File lib/etcdv3/namespace/watch.rb, line 6 def initialize(hostname, credentials, timeout, namespace, metadata = {}) @stub = Etcdserverpb::Watch::Stub.new(hostname, credentials) @timeout = timeout @namespace = namespace @metadata = metadata end
Public Instance Methods
deadline(timeout)
click to toggle source
# File lib/etcdv3/namespace/watch.rb, line 33 def deadline(timeout) from_relative_time(timeout || @timeout) end
watch(key, range_end, start_revision, block, timeout: nil)
click to toggle source
# File lib/etcdv3/namespace/watch.rb, line 13 def watch(key, range_end, start_revision, block, timeout: nil) key = prepend_prefix(@namespace, key) range_end = prepend_prefix(@namespace, range_end) if range_end create_req = Etcdserverpb::WatchCreateRequest.new(key: key) create_req.range_end = range_end if range_end create_req.start_revision = start_revision if start_revision watch_req = Etcdserverpb::WatchRequest.new(create_request: create_req) events = nil @stub.watch([watch_req], metadata: @metadata, deadline: deadline(timeout)).each do |resp| next if resp.events.empty? if block block.call(strip_prefix_from_events(@namespace, resp.events)) else events = strip_prefix_from_events(@namespace, resp.events) break end end events end