Class: Binpacker::Orchestrator

Inherits:
Object
  • Object
show all
Defined in:
lib/binpacker/orchestrator.rb

Constant Summary collapse

BATCH_SIZE =
10

Instance Method Summary collapse

Constructor Details

#initialize(config, passthrough: [], quiet: false) ⇒ Orchestrator

Returns a new instance of Orchestrator.



7
8
9
10
11
# File 'lib/binpacker/orchestrator.rb', line 7

def initialize(config, passthrough: [], quiet: false)
  @config = config
  @passthrough = passthrough
  @quiet = quiet
end

Instance Method Details

#runObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/binpacker/orchestrator.rb', line 13

def run
  tests = discover
  timing = Timing.new(@config.timing_file)
  timings = timing.load_with_fallback(tests)

  scheduler = Scheduler.for(@config.scheduler["algorithm"])
  queues = scheduler.partition(
    tests: tests,
    worker_count: @config.worker_count,
    timings: timings
  )

  runner_class = TestRunner.for(@config.test_runner)
  workers = queues.map.with_index do |queue, idx|
    Worker.new(idx, runner_class, passthrough: @passthrough, quiet: @quiet).tap(&:start)
  end

  if @config.scheduler["steal_enabled"]
    run_dynamic(workers, queues, timing, tests)
  else
    run_static(workers, queues, timing, tests)
  end
end