Class: RemoteService::WorkerPool
- Inherits:
-
Object
- Object
- RemoteService::WorkerPool
- Defined in:
- lib/remote_service/worker_pool.rb
Instance Attribute Summary collapse
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
-
#threads ⇒ Object
readonly
Returns the value of attribute threads.
Instance Method Summary collapse
- #exit ⇒ Object
-
#initialize(worker_count, monitor_interval) ⇒ WorkerPool
constructor
A new instance of WorkerPool.
- #join ⇒ Object
- #run(*args, &block) ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(worker_count, monitor_interval) ⇒ WorkerPool
Returns a new instance of WorkerPool.
5 6 7 8 9 10 |
# File 'lib/remote_service/worker_pool.rb', line 5 def initialize(worker_count, monitor_interval) @worker_count = worker_count @monitor_interval = monitor_interval @threads = [] @queue = ::Queue.new end |
Instance Attribute Details
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
3 4 5 |
# File 'lib/remote_service/worker_pool.rb', line 3 def queue @queue end |
#threads ⇒ Object (readonly)
Returns the value of attribute threads.
3 4 5 |
# File 'lib/remote_service/worker_pool.rb', line 3 def threads @threads end |
Instance Method Details
#exit ⇒ Object
29 30 31 32 33 34 |
# File 'lib/remote_service/worker_pool.rb', line 29 def exit threads.each do |thread| thread.exit end monitor_thread.exit end |
#join ⇒ Object
22 23 24 25 26 27 |
# File 'lib/remote_service/worker_pool.rb', line 22 def join threads.each do |thread| thread.join end monitor_thread.join end |
#run(*args, &block) ⇒ Object
12 13 14 |
# File 'lib/remote_service/worker_pool.rb', line 12 def run(*args, &block) queue.push({ args: args, callable: block }) end |
#start ⇒ Object
16 17 18 19 20 |
# File 'lib/remote_service/worker_pool.rb', line 16 def start spawn_workers monitor_thread RemoteService.logger.info "WORKER POOL - WORKERS: #{threads.size}" end |