Class: Marloss::Locker
- Inherits:
-
Object
- Object
- Marloss::Locker
- Defined in:
- lib/marloss/locker.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#store ⇒ Object
readonly
Returns the value of attribute store.
Instance Method Summary collapse
-
#initialize(store, name) ⇒ Locker
constructor
A new instance of Locker.
- #obtain_lock ⇒ Object
- #refresh_lock ⇒ Object
- #release_lock ⇒ Object
- #wait_until_lock_obtained(sleep_seconds: 3) ⇒ Object
Constructor Details
#initialize(store, name) ⇒ Locker
Returns a new instance of Locker.
8 9 10 11 |
# File 'lib/marloss/locker.rb', line 8 def initialize(store, name) @store = store @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/marloss/locker.rb', line 6 def name @name end |
#store ⇒ Object (readonly)
Returns the value of attribute store.
6 7 8 |
# File 'lib/marloss/locker.rb', line 6 def store @store end |
Instance Method Details
#obtain_lock ⇒ Object
13 14 15 |
# File 'lib/marloss/locker.rb', line 13 def obtain_lock store.create_lock(name) end |
#refresh_lock ⇒ Object
17 18 19 |
# File 'lib/marloss/locker.rb', line 17 def refresh_lock store.refresh_lock(name) end |
#release_lock ⇒ Object
21 22 23 |
# File 'lib/marloss/locker.rb', line 21 def release_lock store.delete_lock(name) end |
#wait_until_lock_obtained(sleep_seconds: 3) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/marloss/locker.rb', line 25 def wait_until_lock_obtained(sleep_seconds: 3) store.create_lock(name) rescue LockNotObtainedError sleep(sleep_seconds) retry end |