Sha256: bb1a93664d99f38463ce604503f01dde5493058d0e4bbd4afcc73060b0807a8d

Contents?: true

Size: 1.24 KB

Versions: 7

Compression:

Stored size: 1.24 KB

Contents

class Etcdv3::Namespace
  class Watch
    include GRPC::Core::TimeConsts
    include Etcdv3::Namespace::Utilities

    def initialize(hostname, credentials, timeout, namespace, metadata = {})
      @stub = Etcdserverpb::Watch::Stub.new(hostname, credentials)
      @timeout = timeout
      @namespace = namespace
      @metadata = metadata
    end

    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

    def deadline(timeout)
      from_relative_time(timeout || @timeout)
    end

  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
rubypitaya-3.12.5 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3/namespace/watch.rb
rubypitaya-3.12.4 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3/namespace/watch.rb
rubypitaya-3.12.3 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3/namespace/watch.rb
rubypitaya-3.12.2 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3/namespace/watch.rb
etcdv3-0.11.5 lib/etcdv3/namespace/watch.rb
etcdv3-0.11.4 lib/etcdv3/namespace/watch.rb
etcdv3-0.11.3 lib/etcdv3/namespace/watch.rb