Sha256: 583e5bf92615442fbafb56d993360944e63b9782991baad4aedd9078b81357a6

Contents?: true

Size: 964 Bytes

Versions: 5

Compression:

Stored size: 964 Bytes

Contents

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

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

    def lock(name, lease_id, timeout: nil)
      name = prepend_prefix(@namespace, name)
      request = V3lockpb::LockRequest.new(name: name, lease: lease_id)
      resp = @stub.lock(request, metadata: @metadata, deadline: deadline(timeout))
      strip_prefix_from_lock(@namespace, resp)
    end

    def unlock(key, timeout: nil)
      key = prepend_prefix(@namespace, key)
      request = V3lockpb::UnlockRequest.new(key: key)
      @stub.unlock(request, metadata: @metadata, deadline: deadline(timeout))
    end

    private

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

Version data entries

5 entries across 5 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/lock.rb
rubypitaya-3.12.4 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3/namespace/lock.rb
rubypitaya-3.12.3 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3/namespace/lock.rb
rubypitaya-3.12.2 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3/namespace/lock.rb
etcdv3-0.11.5 lib/etcdv3/namespace/lock.rb