Class: SongkickQueue::Worker

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(process_name, consumer_classes = []) ⇒ Worker

Returns a new instance of Worker

Parameters:

  • process_name (String)

    of the custom process name to use

  • consumer_classes (Array<Class>, Class) (defaults to: [])

    of consumer class names



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_classesObject (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_nameObject (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

#runObject

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