class ActiveJob::Locking::Adapters::Redlock

Public Instance Methods

create_lock_manager() click to toggle source
# File lib/activejob/locking/adapters/redlock.rb, line 7
def create_lock_manager
  mapped_options = self.options.adapter_options
  mapped_options[:retry_count] = 2 # Try to get the lock and then try again when timeout is expiring--
  mapped_options[:retry_delay] = self.options.lock_acquire_time * 1000 # convert from seconds to milliseconds

  ::Redlock::Client.new(self.options.hosts, mapped_options)
end
lock() click to toggle source
# 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() click to toggle source
# File lib/activejob/locking/adapters/redlock.rb, line 19
def unlock
  self.lock_manager.unlock(self.lock_token.symbolize_keys)
  self.lock_token = nil
end