Class: Faktory::Fetcher
- Inherits:
-
Object
- Object
- Faktory::Fetcher
- Defined in:
- lib/faktory/fetch.rb
Instance Method Summary collapse
-
#initialize(options) ⇒ Fetcher
constructor
A new instance of Fetcher.
-
#queues_cmd ⇒ Object
Creating the pop command takes into account any configured queue weights.
- #retrieve_work ⇒ Object
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() @strictly_ordered_queues = !![:strict] @queues = [:queues] @queues = @queues.uniq if @strictly_ordered_queues end |
Instance Method Details
#queues_cmd ⇒ Object
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_work ⇒ Object
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 |