Class: Barbeque::RetryPoller

Inherits:
Object
  • Object
show all
Defined in:
lib/barbeque/retry_poller.rb

Instance Method Summary collapse

Constructor Details

#initialize(job_queue) ⇒ RetryPoller

Returns a new instance of RetryPoller.



6
7
8
9
# File 'lib/barbeque/retry_poller.rb', line 6

def initialize(job_queue)
  @job_queue      = job_queue
  @stop_requested = false
end

Instance Method Details

#runObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/barbeque/retry_poller.rb', line 11

def run
  Barbeque::JobRetry
    .joins(:job_execution)
    .running
    .merge(Barbeque::JobExecution.where(job_queue: @job_queue))
    .find_in_batches do |job_retries|
    job_retries.shuffle.each do |job_retry|
      if @stop_requested
        return
      end
      job_retry.with_lock do
        if job_retry.running?
          poll(job_retry)
        end
      end
    end
  end
  sleep 1
end

#stopObject



31
32
33
# File 'lib/barbeque/retry_poller.rb', line 31

def stop
  @stop_requested = true
end