Class: Etcdv3::Namespace::Watch
- Includes:
- Utilities, GRPC::Core::TimeConsts
- Defined in:
- lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3/namespace/watch.rb
Instance Method Summary collapse
- #deadline(timeout) ⇒ Object
-
#initialize(hostname, credentials, timeout, namespace, metadata = {}) ⇒ Watch
constructor
A new instance of Watch.
- #watch(key, range_end, start_revision, block, timeout: nil) ⇒ Object
Methods included from Utilities
#delete_prefix, #prepend_prefix, #strip_prefix, #strip_prefix_from_events, #strip_prefix_from_lock
Methods included from GRPC::Core::TimeConsts
Constructor Details
#initialize(hostname, credentials, timeout, namespace, metadata = {}) ⇒ Watch
Returns a new instance of Watch.
6 7 8 9 10 11 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3/namespace/watch.rb', line 6 def initialize(hostname, credentials, timeout, namespace, = {}) @stub = Etcdserverpb::Watch::Stub.new(hostname, credentials) @timeout = timeout @namespace = namespace @metadata = end |
Instance Method Details
#deadline(timeout) ⇒ Object
33 34 35 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/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) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/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 |