Class: SongkickQueue::Worker
- Inherits:
-
Object
- Object
- SongkickQueue::Worker
- Defined in:
- lib/songkick_queue/worker.rb
Instance Attribute Summary collapse
-
#consumer_classes ⇒ Object
readonly
Returns the value of attribute consumer_classes.
-
#process_name ⇒ Object
readonly
Returns the value of attribute process_name.
Instance Method Summary collapse
-
#initialize(process_name, consumer_classes = []) ⇒ Worker
constructor
A new instance of Worker.
-
#run ⇒ Object
Subscribes the consumers classes to their defined message queues and blocks until all the work pool consumers have finished.
Constructor Details
#initialize(process_name, consumer_classes = []) ⇒ Worker
Returns a new instance of Worker.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/songkick_queue/worker.rb', line 7 def initialize(process_name, consumer_classes = []) @process_name = process_name @consumer_classes = Array(consumer_classes) if @consumer_classes.empty? fail ArgumentError, 'no consumer classes given to Worker' end @client = Client.new end |
Instance Attribute Details
#consumer_classes ⇒ Object (readonly)
Returns the value of attribute consumer_classes.
3 4 5 |
# File 'lib/songkick_queue/worker.rb', line 3 def consumer_classes @consumer_classes end |
#process_name ⇒ Object (readonly)
Returns the value of attribute process_name.
3 4 5 |
# File 'lib/songkick_queue/worker.rb', line 3 def process_name @process_name end |
Instance Method Details
#run ⇒ Object
Subscribes the consumers classes to their defined message queues and blocks until all the work pool consumers have finished. Also sets up signal catching for graceful exits no interrupt
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/songkick_queue/worker.rb', line 21 def run set_process_name consumer_classes.each do |consumer_class| subscribe_to_queue(consumer_class) end setup_signal_catching stop_if_signal_caught channel.work_pool.join end |