Class: Raif::Evals::WorkerPool::State
- Inherits:
-
Object
- Object
- Raif::Evals::WorkerPool::State
- Defined in:
- lib/raif/evals/worker_pool.rb
Overview
The pool's shared mutable state, behind one mutex.
Instance Attribute Summary collapse
-
#failure ⇒ Object
readonly
Returns the value of attribute failure.
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#results ⇒ Object
readonly
Returns the value of attribute results.
Instance Method Summary collapse
-
#fail!(error) ⇒ Object
First failure wins: the ones that follow are usually the same provider outage seen by the other workers.
-
#initialize(items:) ⇒ State
constructor
A new instance of State.
- #stop! ⇒ Object
-
#take ⇒ Object
The index of the next item to run, or nil once the list is exhausted or the run is stopping.
Constructor Details
#initialize(items:) ⇒ State
Returns a new instance of State.
76 77 78 79 80 81 82 83 |
# File 'lib/raif/evals/worker_pool.rb', line 76 def initialize(items:) @items = items @results = Array.new(items.size) @next_index = 0 @stopped = false @failure = nil @mutex = Mutex.new end |
Instance Attribute Details
#failure ⇒ Object (readonly)
Returns the value of attribute failure.
74 75 76 |
# File 'lib/raif/evals/worker_pool.rb', line 74 def failure @failure end |
#items ⇒ Object (readonly)
Returns the value of attribute items.
74 75 76 |
# File 'lib/raif/evals/worker_pool.rb', line 74 def items @items end |
#results ⇒ Object (readonly)
Returns the value of attribute results.
74 75 76 |
# File 'lib/raif/evals/worker_pool.rb', line 74 def results @results end |
Instance Method Details
#fail!(error) ⇒ Object
First failure wins: the ones that follow are usually the same provider outage seen by the other workers.
102 103 104 105 106 107 |
# File 'lib/raif/evals/worker_pool.rb', line 102 def fail!(error) @mutex.synchronize do @stopped = true @failure ||= error end end |
#stop! ⇒ Object
96 97 98 |
# File 'lib/raif/evals/worker_pool.rb', line 96 def stop! @mutex.synchronize { @stopped = true } end |
#take ⇒ Object
The index of the next item to run, or nil once the list is exhausted or the run is stopping. Deliberately checked between items rather than mid-item: an execution that has already paid for its inference should finish and be recorded.
88 89 90 91 92 93 94 |
# File 'lib/raif/evals/worker_pool.rb', line 88 def take @mutex.synchronize do return if @stopped || @next_index >= @items.size @next_index.tap { @next_index += 1 } end end |