class Cuetip::WorkerGroup
Attributes
quantity[R]
threads[R]
workers[R]
Public Class Methods
new(quantity, queues)
click to toggle source
# File lib/cuetip/worker_group.rb, line 15 def initialize(quantity, queues) @quantity = quantity @queues = queues || [] @workers = {} @threads = {} end
Public Instance Methods
set_process_name()
click to toggle source
# File lib/cuetip/worker_group.rb, line 49 def set_process_name thread_names = @workers.values.map(&:status) Process.setproctitle("Cuetip: #{thread_names.inspect}") end
start()
click to toggle source
# File lib/cuetip/worker_group.rb, line 22 def start Cuetip.logger.info "Starting #{@quantity} Cuetip workers" if @queues.any? @queues.each { |q| Cuetip.logger.info "-> Joined queue: #{q.to_s}" } end exit_trap = proc do @workers.each { |_, worker| worker.request_exit! } puts 'Exiting...' end trap('INT', &exit_trap) trap('TERM', &exit_trap) @quantity.times do |i| @workers[i] = Worker.new(self, i, @queues) Cuetip.logger.info "-> Starting worker #{i}" @threads[i] = Thread.new(@workers[i]) do |worker| run_callbacks :run_worker do worker.run end end @threads[i].abort_on_exception = true end @threads.values.each(&:join) end