Class: ActiveJob::Locking::Adapters::RedisSemaphore

Inherits:
Base
  • Object
show all
Defined in:
lib/activejob/locking/adapters/redis-semaphore.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!

Constructor Details

This class inherits a constructor from ActiveJob::Locking::Adapters::Base

Instance Method Details

#create_lock_managerObject



7
8
9
10
11
12
13
# File 'lib/activejob/locking/adapters/redis-semaphore.rb', line 7

def create_lock_manager
  mapped_options = {host: self.options.hosts.first,
                    resources: 1,
                    stale_client_timeout: self.options.lock_time}.merge(self.options.adapter_options)

  Redis::Semaphore.new(self.key, mapped_options)
end

#lockObject



15
16
17
# File 'lib/activejob/locking/adapters/redis-semaphore.rb', line 15

def lock
  self.lock_token = self.lock_manager.lock(self.options.lock_acquire_time)
end

#unlockObject



19
20
21
22
# File 'lib/activejob/locking/adapters/redis-semaphore.rb', line 19

def unlock
  self.lock_manager.signal(self.lock_token)
  self.lock_token = nil
end