Class: Upman::Core::Worker
- Inherits:
-
Object
- Object
- Upman::Core::Worker
- Includes:
- Utils::Dynload, Utils::Helper
- Defined in:
- lib/upman/core/worker.rb
Instance Attribute Summary collapse
-
#worker_threads ⇒ Object
Returns the value of attribute worker_threads.
-
#workers ⇒ Object
Returns the value of attribute workers.
Instance Method Summary collapse
-
#initialize ⇒ Worker
constructor
A new instance of Worker.
- #register_worker ⇒ Object
- #run! ⇒ Object
- #shutdown ⇒ Object
Methods included from Utils::Dynload
Methods included from Utils::Helper
Constructor Details
Instance Attribute Details
#worker_threads ⇒ Object
Returns the value of attribute worker_threads.
8 9 10 |
# File 'lib/upman/core/worker.rb', line 8 def worker_threads @worker_threads end |
#workers ⇒ Object
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_worker ⇒ Object
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! @workers.each do |worker| @worker_threads << Thread.new do worker.run! end end @worker_threads.each { |t| t.join } end |
#shutdown ⇒ Object
30 31 32 33 |
# File 'lib/upman/core/worker.rb', line 30 def shutdown info "Stopping Worker Threads" @stop_signal = false end |