Class: Faktory::Fetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/faktory/fetch.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Fetcher

Returns a new instance of Fetcher.



19
20
21
22
23
# File 'lib/faktory/fetch.rb', line 19

def initialize(options)
  @strictly_ordered_queues = !!options[:strict]
  @queues = options[:queues]
  @queues = @queues.uniq if @strictly_ordered_queues
end

Instance Method Details

#queues_cmdObject

Creating the pop command takes into account any configured queue weights. By default pop returns data from the first queue that has pending elements. We recreate the queue command each time we invoke pop to honor weights and avoid queue starvation.



35
36
37
38
39
40
41
# File 'lib/faktory/fetch.rb', line 35

def queues_cmd
  if @strictly_ordered_queues
    @queues
  else
    @queues.shuffle.uniq
  end
end

#retrieve_workObject



25
26
27
28
# File 'lib/faktory/fetch.rb', line 25

def retrieve_work
  work = Faktory.server { |conn| conn.fetch(*queues_cmd) }
  UnitOfWork.new(work) if work
end