Class: Polyrun::Partition::Constraints
- Inherits:
-
Object
- Object
- Polyrun::Partition::Constraints
- Defined in:
- lib/polyrun/partition/constraints.rb
Overview
Hard constraints for plan assignment (spec_queue.md): pins, serial globs. Pins win over serial_glob. First matching pin glob wins.
Instance Attribute Summary collapse
-
#pin_map ⇒ Object
readonly
Returns the value of attribute pin_map.
-
#serial_globs ⇒ Object
readonly
Returns the value of attribute serial_globs.
-
#serial_shard ⇒ Object
readonly
Returns the value of attribute serial_shard.
Class Method Summary collapse
Instance Method Summary collapse
- #any? ⇒ Boolean
-
#forced_shard_for(path) ⇒ Object
Returns Integer shard index if constrained, or nil if free to place by LPT/HRW.
-
#initialize(pin_map: {}, serial_globs: [], serial_shard: 0, root: nil) ⇒ Constraints
constructor
A new instance of Constraints.
Constructor Details
#initialize(pin_map: {}, serial_globs: [], serial_shard: 0, root: nil) ⇒ Constraints
Returns a new instance of Constraints.
11 12 13 14 15 16 |
# File 'lib/polyrun/partition/constraints.rb', line 11 def initialize(pin_map: {}, serial_globs: [], serial_shard: 0, root: nil) @pin_map = pin_map.transform_keys(&:to_s).transform_values { |v| Integer(v) } @serial_globs = Array(serial_globs).map(&:to_s) @serial_shard = Integer(serial_shard) @root = root ? File.(root) : Dir.pwd end |
Instance Attribute Details
#pin_map ⇒ Object (readonly)
Returns the value of attribute pin_map.
6 7 8 |
# File 'lib/polyrun/partition/constraints.rb', line 6 def pin_map @pin_map end |
#serial_globs ⇒ Object (readonly)
Returns the value of attribute serial_globs.
6 7 8 |
# File 'lib/polyrun/partition/constraints.rb', line 6 def serial_globs @serial_globs end |
#serial_shard ⇒ Object (readonly)
Returns the value of attribute serial_shard.
6 7 8 |
# File 'lib/polyrun/partition/constraints.rb', line 6 def serial_shard @serial_shard end |
Class Method Details
.from_hash(h, root: nil) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/polyrun/partition/constraints.rb', line 18 def self.from_hash(h, root: nil) h = h.transform_keys(&:to_s) if h.is_a?(Hash) return new(root: root) unless h.is_a?(Hash) pins = h["pin"] || h["pins"] || {} serial = h["serial_glob"] || h["serial_globs"] || [] serial_shard = h["serial_shard"] || 0 new( pin_map: pins.is_a?(Hash) ? pins : {}, serial_globs: serial.is_a?(Array) ? serial : [], serial_shard: serial_shard, root: root ) end |
Instance Method Details
#any? ⇒ Boolean
55 56 57 |
# File 'lib/polyrun/partition/constraints.rb', line 55 def any? @pin_map.any? || @serial_globs.any? end |
#forced_shard_for(path) ⇒ Object
Returns Integer shard index if constrained, or nil if free to place by LPT/HRW.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/polyrun/partition/constraints.rb', line 34 def forced_shard_for(path) rel = path.to_s abs = File.(rel, @root) @pin_map.each do |pattern, shard| next if pattern.to_s.empty? if match_pattern?(pattern.to_s, rel, abs) return shard end end @serial_globs.each do |g| if match_pattern?(g, rel, abs) return @serial_shard end end nil end |