Class: Marloss::Locker

Inherits:
Object
  • Object
show all
Defined in:
lib/marloss/locker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/marloss/locker.rb', line 6

def name
  @name
end

#storeObject (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_lockObject



13
14
15
# File 'lib/marloss/locker.rb', line 13

def obtain_lock
  store.create_lock(name)
end

#refresh_lockObject



17
18
19
# File 'lib/marloss/locker.rb', line 17

def refresh_lock
  store.refresh_lock(name)
end

#release_lockObject



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