Sha256: 8a8e81deffedd13423ad9b3182471c17fcc7b36034f5c1f429777abc7df46621

Contents?: true

Size: 981 Bytes

Versions: 9

Compression:

Stored size: 981 Bytes

Contents

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

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

    def watch(key, range_end, start_revision, block, timeout: nil)
      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(resp.events)
        else
          events = resp.events
          break
        end
      end
      events
    end

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

Version data entries

9 entries across 9 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/watch.rb
rubypitaya-3.12.4 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3/watch.rb
rubypitaya-3.12.3 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3/watch.rb
rubypitaya-3.12.2 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3/watch.rb
etcdv3-0.11.5 lib/etcdv3/watch.rb
etcdv3-0.11.4 lib/etcdv3/watch.rb
etcdv3-0.11.3 lib/etcdv3/watch.rb
etcdv3-0.10.2 lib/etcdv3/watch.rb
etcdv3-0.10.1 lib/etcdv3/watch.rb