Class: TestRunner::ResourcePool::CapacitySource
- Inherits:
-
Object
- Object
- TestRunner::ResourcePool::CapacitySource
- Defined in:
- lib/test-runner/resource_pool.rb
Instance Attribute Summary collapse
-
#max_value ⇒ Object
readonly
protected
Returns the value of attribute max_value.
Instance Method Summary collapse
- #current ⇒ Object
-
#initialize(max_value:, reserve:, detector:, overcommit:) ⇒ CapacitySource
constructor
A new instance of CapacitySource.
- #limit(detected) ⇒ Object protected
- #overcommit(detected) ⇒ Object protected
Constructor Details
#initialize(max_value:, reserve:, detector:, overcommit:) ⇒ CapacitySource
Returns a new instance of CapacitySource.
36 37 38 39 40 41 |
# File 'lib/test-runner/resource_pool.rb', line 36 def initialize(max_value:, reserve:, detector:, overcommit:) @max_value = max_value @reserve = reserve @detector = detector @overcommit = overcommit end |
Instance Attribute Details
#max_value ⇒ Object (readonly, protected)
Returns the value of attribute max_value.
51 52 53 |
# File 'lib/test-runner/resource_pool.rb', line 51 def max_value @max_value end |
Instance Method Details
#current ⇒ Object
43 44 45 46 47 |
# File 'lib/test-runner/resource_pool.rb', line 43 def current detected = @detector.call ResourcePool.capacity(limit(overcommit(detected)), @reserve) end |
#limit(detected) ⇒ Object (protected)
59 60 61 62 63 64 65 66 67 |
# File 'lib/test-runner/resource_pool.rb', line 59 def limit(detected) if detected && max_value [detected, max_value].min elsif detected detected else max_value end end |
#overcommit(detected) ⇒ Object (protected)
53 54 55 56 57 |
# File 'lib/test-runner/resource_pool.rb', line 53 def overcommit(detected) return nil if detected.nil? (detected * @overcommit).floor end |