Class: DisqueJockey::WorkerPool
- Inherits:
-
Object
- Object
- DisqueJockey::WorkerPool
- Defined in:
- lib/disque_jockey/worker_pool.rb
Instance Method Summary collapse
-
#initialize(worker_class) ⇒ WorkerPool
constructor
A new instance of WorkerPool.
- #work! ⇒ Object
Constructor Details
#initialize(worker_class) ⇒ WorkerPool
Returns a new instance of WorkerPool.
4 5 6 7 8 9 |
# File 'lib/disque_jockey/worker_pool.rb', line 4 def initialize(worker_class) @worker_class = worker_class @pool = Queue.new @broker = Broker.new(DisqueJockey.configuration.nodes) build_worker_pool end |
Instance Method Details
#work! ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/disque_jockey/worker_pool.rb', line 11 def work! endless_loop do # fetching from broker blocks until a job is returned _, job_id, job = @broker.(@worker_class.queue_name) with_worker do |worker| Thread.new { handle_job(worker, job, job_id) } end end end |