Class: Infrastruct::Manager
- Inherits:
-
Object
- Object
- Infrastruct::Manager
- Defined in:
- lib/infrastruct/manager.rb
Instance Attribute Summary collapse
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
Instance Method Summary collapse
- #enqueue(*args, &block) ⇒ Object
-
#initialize(worker_factory, thread_pool:) ⇒ Manager
constructor
A new instance of Manager.
- #run ⇒ Object
Constructor Details
#initialize(worker_factory, thread_pool:) ⇒ Manager
5 6 7 8 9 10 |
# File 'lib/infrastruct/manager.rb', line 5 def initialize(worker_factory, thread_pool:) @worker_factory = worker_factory @thread_pool = thread_pool @results = Array.new @mutex = Mutex.new end |
Instance Attribute Details
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
3 4 5 |
# File 'lib/infrastruct/manager.rb', line 3 def queue @queue end |
Instance Method Details
#enqueue(*args, &block) ⇒ Object
12 13 14 |
# File 'lib/infrastruct/manager.rb', line 12 def enqueue(*args, &block) @thread_pool.enqueue([args, block]) end |
#run ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/infrastruct/manager.rb', line 16 def run @thread_pool.run do |params| begin worker = @worker_factory.new result = worker.perform(*params[0], ¶ms[1]) @mutex.synchronize do @results.push(result) end rescue @thread_pool.enqueue(params) end end worker = @worker_factory.new worker.collect(@results) end |