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.
13 14 15 16 17 18 |
# File 'lib/polyrun/partition/constraints.rb', line 13 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.
8 9 10 |
# File 'lib/polyrun/partition/constraints.rb', line 8 def pin_map @pin_map end |
#serial_globs ⇒ Object (readonly)
Returns the value of attribute serial_globs.
8 9 10 |
# File 'lib/polyrun/partition/constraints.rb', line 8 def serial_globs @serial_globs end |
#serial_shard ⇒ Object (readonly)
Returns the value of attribute serial_shard.
8 9 10 |
# File 'lib/polyrun/partition/constraints.rb', line 8 def serial_shard @serial_shard end |
Class Method Details
.from_hash(h, root: nil) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/polyrun/partition/constraints.rb', line 20 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
66 67 68 |
# File 'lib/polyrun/partition/constraints.rb', line 66 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. For path:line items (example granularity), also matches pins/globs against the file path only.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/polyrun/partition/constraints.rb', line 37 def forced_shard_for(path) rel = path.to_s abs = File.(rel, @root) variants = [rel, abs] if (fp = TimingKeys.file_part_for_constraint(rel)) variants << fp variants << File.(fp, @root) end variants.uniq! @pin_map.each do |pattern, shard| next if pattern.to_s.empty? variants.each do |rel_i| abs_i = File.(rel_i, @root) return shard if match_pattern?(pattern.to_s, rel_i, abs_i) end end @serial_globs.each do |g| variants.each do |rel_i| abs_i = File.(rel_i, @root) return @serial_shard if match_pattern?(g, rel_i, abs_i) end end nil end |