Module: Zlk::Lockable
- Defined in:
- lib/zlk/lockable.rb
Instance Method Summary collapse
- #lock ⇒ Object
- #lock_key ⇒ Object
- #lock_timeout ⇒ Object
- #locked? ⇒ Boolean
- #run_exclusively ⇒ Object
- #run_with_timeout! ⇒ Object
Instance Method Details
#lock ⇒ Object
29 30 31 |
# File 'lib/zlk/lockable.rb', line 29 def lock Zlk.create_lock(lock_key) end |
#lock_key ⇒ Object
3 4 5 6 7 8 9 10 11 |
# File 'lib/zlk/lockable.rb', line 3 def lock_key suffix = if respond_to?(:id) id else respond_to?(:uuid) ? uuid : fail("Define #{self.class}#lock_key") end "#{self.class}-#{suffix}" end |
#lock_timeout ⇒ Object
21 22 23 |
# File 'lib/zlk/lockable.rb', line 21 def lock_timeout 10 end |
#locked? ⇒ Boolean
25 26 27 |
# File 'lib/zlk/lockable.rb', line 25 def locked? !lock.acquirable? end |
#run_exclusively ⇒ Object
13 14 15 |
# File 'lib/zlk/lockable.rb', line 13 def run_exclusively lock.run_exclusively { yield } end |
#run_with_timeout! ⇒ Object
17 18 19 |
# File 'lib/zlk/lockable.rb', line 17 def run_with_timeout! lock.with_timeout!(lock_timeout) { yield } end |