Class: Resqued::Config::Worker
- Defined in:
- lib/resqued/config/worker.rb
Overview
A config handler that builds workers.
No worker processes are spawned by this class.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Worker
constructor
Public.
-
#queue(*queues) ⇒ Object
DSL: Define a queue for the worker_pool to work from.
-
#worker(*queues) ⇒ Object
DSL: Create a worker for the exact queues listed.
-
#worker_factory(&block) ⇒ Object
DSL: Define a factory Proc used to create Resque::Workers.
-
#worker_pool(count, *queues) ⇒ Object
DSL: Set up a pool of workers.
Methods inherited from Base
Methods included from Dsl
#after_exit, #after_fork, #before_fork
Constructor Details
Instance Method Details
#queue(*queues) ⇒ Object
DSL: Define a queue for the worker_pool to work from.
queue 'one'
queue '*'
queue 'four-a', 'four-b', :percent => 10
queue 'five', :count => 5
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/resqued/config/worker.rb', line 53 def queue(*queues) = queues.last.is_a?(Hash) ? queues.pop : {} concurrency = case when Hash if percent = [:percent] percent * 0.01 elsif count = [:count] count else 1.0 end else 1.0 end queues.each { |queue| @pool_queues[queue] = concurrency } end |
#worker(*queues) ⇒ Object
DSL: Create a worker for the exact queues listed.
worker 'one', :interval => 1
21 22 23 24 25 26 27 |
# File 'lib/resqued/config/worker.rb', line 21 def worker(*queues) = queues.last.is_a?(Hash) ? queues.pop.dup : {} queues = queues.flatten queues = ["*"] if queues.empty? queues = queues.shuffle if .delete(:shuffle_queues) @workers << @worker_class.new(.merge(@worker_options).merge(queues: queues)) end |
#worker_factory(&block) ⇒ Object
DSL: Define a factory Proc used to create Resque::Workers. The factory Proc receives a list of queues as an argument.
worker_factory { |queues| Resque::Worker.new(*queues) }
43 44 45 |
# File 'lib/resqued/config/worker.rb', line 43 def worker_factory(&block) @worker_options.merge!(worker_factory: block) end |
#worker_pool(count, *queues) ⇒ Object
DSL: Set up a pool of workers. Define queues for the members of the pool with ‘queue`.
worker_pool 20, :interval => 1
32 33 34 35 36 37 |
# File 'lib/resqued/config/worker.rb', line 32 def worker_pool(count, *queues) @pool_size = count @pool_options = queues.last.is_a?(Hash) ? queues.pop : {} @pool_queues = {} queues.each { |q| queue q } end |