Class: Chore::Strategy::SingleConsumerStrategy
- Inherits:
-
Object
- Object
- Chore::Strategy::SingleConsumerStrategy
- Defined in:
- lib/chore/strategies/consumer/single_consumer_strategy.rb
Overview
Consumer strategy for requesting batches of work in a linear fashion.
Ideally used for running a single Chore job locally in a development
environment where performance or throughput may not matter.
SingleConsumerStrategy
will raise an exception if you're
configured to listen for more than 1 queue
Instance Method Summary collapse
-
#fetch ⇒ Object
Begins fetching from the configured queue by way of the configured Consumer.
-
#initialize(fetcher, opts = {}) ⇒ SingleConsumerStrategy
constructor
A new instance of SingleConsumerStrategy.
-
#stop! ⇒ Object
Stops consuming messages from the queue.
Constructor Details
#initialize(fetcher, opts = {}) ⇒ SingleConsumerStrategy
Returns a new instance of SingleConsumerStrategy.
8 9 10 |
# File 'lib/chore/strategies/consumer/single_consumer_strategy.rb', line 8 def initialize(fetcher, opts={}) @fetcher = fetcher end |
Instance Method Details
#fetch ⇒ Object
Begins fetching from the configured queue by way of the configured Consumer. This can only be used if you have a single queue which can be kept up with at a relatively low volume. If you have more than a single queue configured, it will raise an exception.
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/chore/strategies/consumer/single_consumer_strategy.rb', line 15 def fetch Chore.logger.debug "Starting up consumer strategy: #{self.class.name}" queues = Chore.config.queues raise "When using SingleConsumerStrategy only one queue can be defined. Queues: #{queues}" unless queues.size == 1 @consumer = Chore.config.consumer.new(queues.first) @consumer.consume do |, , queue_name, queue_timeout, body, previous_attempts| work = UnitOfWork.new(, , queue_name, queue_timeout, body, previous_attempts, @consumer) @fetcher.manager.assign(work) end end |