Class: KnapsackPro::Allocator

Inherits:
Object
  • Object
show all
Defined in:
lib/knapsack_pro/allocator.rb

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Allocator

Returns a new instance of Allocator.



3
4
5
6
7
8
# File 'lib/knapsack_pro/allocator.rb', line 3

def initialize(args)
  @test_files = args.fetch(:test_files)
  @ci_node_total = args.fetch(:ci_node_total)
  @ci_node_index = args.fetch(:ci_node_index)
  @repository_adapter = args.fetch(:repository_adapter)
end

Instance Method Details

#test_file_pathsObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/knapsack_pro/allocator.rb', line 10

def test_file_paths
  action = KnapsackPro::Client::API::V1::BuildDistributions.subset(
    commit_hash: repository_adapter.commit_hash,
    branch: repository_adapter.branch,
    node_total: ci_node_total,
    node_index: ci_node_index,
    test_files: test_files,
  )
  connection = KnapsackPro::Client::Connection.new(action)
  response = connection.call
  if connection.success?
    raise ArgumentError.new(response) if connection.errors?
    KnapsackPro::TestFilePresenter.paths(response['test_files'])
  else
    test_flat_distributor = KnapsackPro::TestFlatDistributor.new(test_files, ci_node_total)
    test_files_for_node_index = test_flat_distributor.test_files_for_node(ci_node_index)
    KnapsackPro::TestFilePresenter.paths(test_files_for_node_index)
  end
end