Class: Rabbithole::Worker
- Inherits:
-
Object
- Object
- Rabbithole::Worker
- Defined in:
- lib/rabbithole/worker.rb
Instance Attribute Summary collapse
-
#number_of_threads ⇒ Object
readonly
Returns the value of attribute number_of_threads.
Instance Method Summary collapse
-
#initialize(number_of_threads = 1) ⇒ Worker
constructor
A new instance of Worker.
- #join ⇒ Object
- #listen_to_queue(queue_name) ⇒ Object
- #stop_listening ⇒ Object
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_threads ⇒ Object (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
#join ⇒ Object
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_listening ⇒ Object
16 17 18 |
# File 'lib/rabbithole/worker.rb', line 16 def stop_listening @channel.consumers.values.each(&:cancel) end |