class Sidekiq::ReliableFetch

Constants

RELIABLE_FETCH_IDLE_TIMEOUT

For reliable fetch we don't use Redis' blocking operations so we inject a regular sleep into the loop.

Attributes

queues_iterator[R]
queues_size[R]

Public Class Methods

new(options) click to toggle source
Calls superclass method Sidekiq::BaseReliableFetch.new
# File lib/sidekiq/reliable_fetch.rb, line 10
def initialize(options)
  super

  @queues_size = queues.size
  @queues_iterator = queues.cycle
end

Private Instance Methods

retrieve_unit_of_work() click to toggle source
# File lib/sidekiq/reliable_fetch.rb, line 19
def retrieve_unit_of_work
  @queues_iterator.rewind if strictly_ordered_queues

  queues_size.times do
    queue = queues_iterator.next

    work = Sidekiq.redis do |conn|
      conn.rpoplpush(queue, self.class.working_queue_name(queue))
    end

    return UnitOfWork.new(queue, work) if work
  end

  # We didn't find a job in any of the configured queues. Let's sleep a bit
  # to avoid uselessly burning too much CPU
  sleep(RELIABLE_FETCH_IDLE_TIMEOUT)

  nil
end