class Sidekiq::SemiReliableFetch

Constants

SEMI_RELIABLE_FETCH_TIMEOUT

We want the fetch operation to timeout every few seconds so the thread can check if the process is shutting down. This constant is only used for semi-reliable fetch.

Public Class Methods

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

  if strictly_ordered_queues
    @queues = @queues.uniq
    @queues << SEMI_RELIABLE_FETCH_TIMEOUT
  end
end

Private Instance Methods

queues_cmd() click to toggle source
# File lib/sidekiq/semi_reliable_fetch.rb, line 33
def queues_cmd
  if strictly_ordered_queues
    @queues
  else
    queues = @queues.shuffle.uniq
    queues << SEMI_RELIABLE_FETCH_TIMEOUT
    queues
  end
end
retrieve_unit_of_work() click to toggle source
# File lib/sidekiq/semi_reliable_fetch.rb, line 20
def retrieve_unit_of_work
  work = Sidekiq.redis { |conn| conn.brpop(*queues_cmd) }
  return unless work

  unit_of_work = UnitOfWork.new(*work)

  Sidekiq.redis do |conn|
    conn.lpush(self.class.working_queue_name(unit_of_work.queue), unit_of_work.job)
  end

  unit_of_work
end