Class: Rabbithole::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/rabbithole/worker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(number_of_threads = 1) ⇒ Worker

Returns a new instance of Worker.



5
6
7
8
9
# File 'lib/rabbithole/worker.rb', line 5

def initialize(number_of_threads = 1)
  @number_of_threads = number_of_threads
  @channel           = Connection.create_channel(number_of_threads)
  @channel.prefetch(number_of_threads * 5)
end

Instance Attribute Details

#number_of_threadsObject (readonly)

Returns the value of attribute number_of_threads.



3
4
5
# File 'lib/rabbithole/worker.rb', line 3

def number_of_threads
  @number_of_threads
end

Instance Method Details

#joinObject



20
21
22
# File 'lib/rabbithole/worker.rb', line 20

def join
  @channel.work_pool.join
end

#listen_to_queue(queue_name) ⇒ Object



11
12
13
14
# File 'lib/rabbithole/worker.rb', line 11

def listen_to_queue(queue_name)
  queue   = Connection.queue(queue_name, @channel)
  start_consumer(queue)
end

#stop_listeningObject



16
17
18
# File 'lib/rabbithole/worker.rb', line 16

def stop_listening
  @channel.consumers.values.each(&:cancel)
end