Class: Upperkut::Manager
- Inherits:
-
Object
- Object
- Upperkut::Manager
- Defined in:
- lib/upperkut/manager.rb
Instance Attribute Summary collapse
-
#concurrency ⇒ Object
readonly
Returns the value of attribute concurrency.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#stopped ⇒ Object
readonly
Returns the value of attribute stopped.
-
#worker ⇒ Object
Returns the value of attribute worker.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Manager
constructor
A new instance of Manager.
- #kill ⇒ Object
- #notify_killed_processor(thread) ⇒ Object
- #run ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Manager
Returns a new instance of Manager.
11 12 13 14 15 16 17 18 |
# File 'lib/upperkut/manager.rb', line 11 def initialize(opts = {}) self.worker = opts.fetch(:worker).constantize @concurrency = opts.fetch(:concurrency, 1) @logger = opts.fetch(:logger, Logging.logger) @stopped = false @threads = [] end |
Instance Attribute Details
#concurrency ⇒ Object (readonly)
Returns the value of attribute concurrency.
9 10 11 |
# File 'lib/upperkut/manager.rb', line 9 def concurrency @concurrency end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
9 10 11 |
# File 'lib/upperkut/manager.rb', line 9 def logger @logger end |
#stopped ⇒ Object (readonly)
Returns the value of attribute stopped.
9 10 11 |
# File 'lib/upperkut/manager.rb', line 9 def stopped @stopped end |
#worker ⇒ Object
Returns the value of attribute worker.
8 9 10 |
# File 'lib/upperkut/manager.rb', line 8 def worker @worker end |
Instance Method Details
#kill ⇒ Object
31 32 33 |
# File 'lib/upperkut/manager.rb', line 31 def kill @threads.each(&:kill) end |
#notify_killed_processor(thread) ⇒ Object
35 36 37 38 |
# File 'lib/upperkut/manager.rb', line 35 def notify_killed_processor(thread) @threads.delete(thread) spawn_thread unless @stopped end |
#run ⇒ Object
20 21 22 23 24 |
# File 'lib/upperkut/manager.rb', line 20 def run @concurrency.times do spawn_thread end end |
#stop ⇒ Object
26 27 28 29 |
# File 'lib/upperkut/manager.rb', line 26 def stop @stopped = true @threads.each(&:stop) end |