Class: SolidQueue::Semaphore::Proxy

Inherits:
Object
  • Object
show all
Defined in:
app/models/solid_queue/semaphore.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(job) ⇒ Proxy

Returns a new instance of Proxy.



38
39
40
# File 'app/models/solid_queue/semaphore.rb', line 38

def initialize(job)
  @job = job
end

Class Method Details

.signal_all(jobs) ⇒ Object



34
35
36
# File 'app/models/solid_queue/semaphore.rb', line 34

def self.signal_all(jobs)
  Semaphore.where(key: jobs.map(&:concurrency_key)).update_all("value = value + 1")
end

Instance Method Details

#signalObject



50
51
52
# File 'app/models/solid_queue/semaphore.rb', line 50

def signal
  attempt_increment
end

#waitObject



42
43
44
45
46
47
48
# File 'app/models/solid_queue/semaphore.rb', line 42

def wait
  if semaphore = Semaphore.find_by(key: key)
    semaphore.value > 0 && attempt_decrement
  else
    attempt_creation
  end
end