Class: Blender::Lock::Zk
- Inherits:
-
Object
- Object
- Blender::Lock::Zk
- Defined in:
- lib/blender/lock/zk.rb
Instance Method Summary collapse
-
#initialize(name, options = {}) ⇒ Zk
constructor
A new instance of Zk.
- #with_lock ⇒ Object
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, = {}) @path = [:path] || name @hosts = [:hosts] || 'localhost:2181' @chroot = [:chroot] || :do_nothing @thread = [:thread] || :single @timeout = [:timeout] || 0 end |
Instance Method Details
#with_lock ⇒ Object
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. end |