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.



27
28
29
# File 'app/models/solid_queue/semaphore.rb', line 27

def initialize(job)
  @job = job
end

Class Method Details

.signal_all(jobs) ⇒ Object



23
24
25
# File 'app/models/solid_queue/semaphore.rb', line 23

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

Instance Method Details

#signalObject



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

def signal
  attempt_increment
end

#waitObject



31
32
33
34
35
36
37
# File 'app/models/solid_queue/semaphore.rb', line 31

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