Class: ActiveJob::Locking::Adapters::Redlock
- Inherits:
-
Base
- Object
- Base
- ActiveJob::Locking::Adapters::Redlock
show all
- Defined in:
- lib/activejob/locking/adapters/redlock.rb
Instance Attribute Summary
Attributes inherited from Base
#key, #lock_manager, #lock_token, #options
Instance Method Summary
collapse
Methods inherited from Base
#initialize, #refresh_lock!
Instance Method Details
#create_lock_manager ⇒ Object
7
8
9
10
11
12
13
|
# File 'lib/activejob/locking/adapters/redlock.rb', line 7
def create_lock_manager
mapped_options = self.options.adapter_options
mapped_options[:retry_count] = 2 mapped_options[:retry_delay] = self.options.lock_acquire_time * 1000
::Redlock::Client.new(self.options.hosts, mapped_options)
end
|
#lock ⇒ Object
15
16
17
|
# File 'lib/activejob/locking/adapters/redlock.rb', line 15
def lock
self.lock_token = self.lock_manager.lock(self.key, self.options.lock_time * 1000)
end
|
#unlock ⇒ Object
19
20
21
22
|
# File 'lib/activejob/locking/adapters/redlock.rb', line 19
def unlock
self.lock_manager.unlock(self.lock_token)
self.lock_token = nil
end
|