Class: Binpacker::LptScheduler

Inherits:
Scheduler show all
Defined in:
lib/binpacker/scheduler.rb

Instance Method Summary collapse

Methods inherited from Scheduler

for

Instance Method Details

#partition(tests:, worker_count:, timings:) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/binpacker/scheduler.rb', line 30

def partition(tests:, worker_count:, timings:)
  queues = Array.new(worker_count) { |i| WorkerQueue.new(i) }
  loads = Array.new(worker_count, 0.0)

  sorted_by_weight(tests, timings).each do |test|
    min_idx = loads.each_with_index.min_by { |load, _| load }.last
    queues[min_idx].push(test)
    loads[min_idx] += weight(test, timings)
  end

  queues
end