Class: Raif::Evals::WorkerPool::Dispatch
- Inherits:
-
Object
- Object
- Raif::Evals::WorkerPool::Dispatch
- Defined in:
- lib/raif/evals/worker_pool.rb
Overview
One run's workers and the items still to hand them. Rails discards the connection pools a child inherits on its first use of them, so nothing here has to close the parent's.
Defined Under Namespace
Classes: Worker
Instance Method Summary collapse
-
#initialize(items:, work:, collect:, dispatched:, setup_worker:) ⇒ Dispatch
constructor
A new instance of Dispatch.
- #run(worker_count:) ⇒ Object
Constructor Details
#initialize(items:, work:, collect:, dispatched:, setup_worker:) ⇒ Dispatch
Returns a new instance of Dispatch.
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/raif/evals/worker_pool.rb', line 59 def initialize(items:, work:, collect:, dispatched:, setup_worker:) @items = items @work = work @collect = collect @dispatched = dispatched @setup_worker = setup_worker @workers = [] @next_index = 0 @in_flight = {} @stopping = false @interrupted = false @failure = nil end |
Instance Method Details
#run(worker_count:) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/raif/evals/worker_pool.rb', line 73 def run(worker_count:) worker_count.times { |i| @workers << fork_worker(i + 1) } @workers.each { |worker| dispatch(worker) } drain raise Interrupt if @interrupted raise @failure if @failure ensure shut_down end |