Class: DisqueJockey::WorkerPool

Inherits:
Object
  • Object
show all
Defined in:
lib/disque_jockey/worker_pool.rb

Instance Method Summary collapse

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.fetch_message_from(@worker_class.queue_name)

    with_worker do |worker|
      Thread.new { handle_job(worker, job, job_id) }
    end

  end
end