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, retries: nil) ⇒ Object
Constructor Details
#initialize(store, name) ⇒ Locker
Returns a new instance of Locker.
7 8 9 10 |
# File 'lib/marloss/locker.rb', line 7 def initialize(store, name) @store = store @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/marloss/locker.rb', line 5 def name @name end |
#store ⇒ Object (readonly)
Returns the value of attribute store.
5 6 7 |
# File 'lib/marloss/locker.rb', line 5 def store @store end |
Instance Method Details
#obtain_lock ⇒ Object
12 13 14 |
# File 'lib/marloss/locker.rb', line 12 def obtain_lock store.create_lock(name) end |
#refresh_lock ⇒ Object
16 17 18 |
# File 'lib/marloss/locker.rb', line 16 def refresh_lock store.refresh_lock(name) end |
#release_lock ⇒ Object
20 21 22 |
# File 'lib/marloss/locker.rb', line 20 def release_lock store.delete_lock(name) end |
#wait_until_lock_obtained(sleep_seconds: 3, retries: nil) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/marloss/locker.rb', line 24 def wait_until_lock_obtained(sleep_seconds: 3, retries: nil) store.create_lock(name) rescue LockNotObtainedError sleep(sleep_seconds) unless retries.nil? retries -= 1 raise if retries.zero? end retry end |