Class: Resque::PickyWorker
- Inherits:
-
Worker
- Object
- Worker
- Resque::PickyWorker
- Defined in:
- lib/resque/picky_worker.rb
Constant Summary collapse
- Error =
Class.new(StandardError)
Class Attribute Summary collapse
-
.chooser ⇒ Object
Something that responds to #call (eg. Proc) and takes a single argument - array of queue names Should return a string which is a valid queue name.
-
.default_max_workers ⇒ Object
Returns the value of attribute default_max_workers.
Class Method Summary collapse
-
.pick_queue ⇒ Object
Returns a string (name of a queue).
- .queue_current(name) ⇒ Object
- .queue_max(name) ⇒ Object
Instance Method Summary collapse
-
#initialize ⇒ PickyWorker
constructor
Invoke the worker class with a randomly picked queue.
Constructor Details
#initialize ⇒ PickyWorker
Invoke the worker class with a randomly picked queue
36 37 38 |
# File 'lib/resque/picky_worker.rb', line 36 def initialize super(PickyWorker.pick_queue) end |
Class Attribute Details
.chooser ⇒ Object
Something that responds to #call (eg. Proc) and takes a single argument - array of queue names Should return a string which is a valid queue name
12 13 14 |
# File 'lib/resque/picky_worker.rb', line 12 def chooser @chooser end |
.default_max_workers ⇒ Object
Returns the value of attribute default_max_workers.
9 10 11 |
# File 'lib/resque/picky_worker.rb', line 9 def default_max_workers @default_max_workers end |
Class Method Details
.pick_queue ⇒ Object
Returns a string (name of a queue)
21 22 23 24 25 |
# File 'lib/resque/picky_worker.rb', line 21 def self.pick_queue cue = chooser.call(Resque.queues) raise(Error, "chooser returned an invalid queue name") unless Resque.queues.include?(cue) cue end |
.queue_current(name) ⇒ Object
31 32 33 |
# File 'lib/resque/picky_worker.rb', line 31 def self.queue_current name all.select {|worker| worker.queues.include?(name) }.size end |
.queue_max(name) ⇒ Object
27 28 29 |
# File 'lib/resque/picky_worker.rb', line 27 def self.queue_max name (Resque::Queue::Metadata.new(name)["max_workers"] || default_max_workers).to_i end |