Class: Blender::Lock::Zk

Inherits:
Object
  • Object
show all
Defined in:
lib/blender/lock/zk.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ Zk

Returns a new instance of Zk.



26
27
28
29
30
31
32
# File 'lib/blender/lock/zk.rb', line 26

def initialize(name, options = {})
  @path = options[:path] || name
  @hosts = options[:hosts] || 'localhost:2181'
  @chroot = options[:chroot] || :do_nothing
  @thread = options[:thread] || :single
  @timeout = options[:timeout] || 0
end

Instance Method Details

#with_lockObject



34
35
36
37
38
39
40
41
42
# File 'lib/blender/lock/zk.rb', line 34

def with_lock
  ZK.open(@hosts) do |zk|
    zk.with_lock(@path, wait: @timeout) do
      yield if block_given?
    end
  end
rescue ZK::Exceptions::LockWaitTimeoutError => e
  raise LockAcquisitionError, e.message
end