Class: Upman::Core::Worker

Inherits:
Object
  • Object
show all
Includes:
Utils::Dynload, Utils::Helper
Defined in:
lib/upman/core/worker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::Dynload

#dynload

Methods included from Utils::Helper

#fail, #info, #success, #warn

Constructor Details

#initializeWorker



10
11
12
13
14
15
16
17
# File 'lib/upman/core/worker.rb', line 10

def initialize
  @stop_signal = true
  @config = ::Upman::Core::Config.daemon
  @workers = []
  @worker_threads = []

  register_worker
end

Instance Attribute Details

#worker_threadsObject

Returns the value of attribute worker_threads.



8
9
10
# File 'lib/upman/core/worker.rb', line 8

def worker_threads
  @worker_threads
end

#workersObject

Returns the value of attribute workers.



8
9
10
# File 'lib/upman/core/worker.rb', line 8

def workers
  @workers
end

Instance Method Details

#register_workerObject



36
37
38
39
40
41
42
43
44
# File 'lib/upman/core/worker.rb', line 36

def register_worker
  @config[:workers].each do |worker|
    require_relative "../../upman/worker/#{worker}"
    ext_obj  = dynload("Upman::Worker::#{worker.split('_').map(&:capitalize).join('')}")
    info "Register Worker Thread Upman::Worker::#{worker.split('_').map(&:capitalize).join('')}"
    ext_class = ext_obj .new
    @workers.append ext_class.register
  end
end

#run!Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/upman/core/worker.rb', line 19

def run!
  show_banner

  @workers.each do |worker|
    @worker_threads << Thread.new do
      worker.run!
    end
  end
  @worker_threads.each { |t| t.join }
end

#shutdownObject



30
31
32
33
# File 'lib/upman/core/worker.rb', line 30

def shutdown
  info "Stopping Worker Threads"
  @stop_signal = false
end