Class: KnapsackPro::QueueAllocator
- Inherits:
-
Object
- Object
- KnapsackPro::QueueAllocator
- Defined in:
- lib/knapsack_pro/queue_allocator.rb
Defined Under Namespace
Classes: Batch
Constant Summary collapse
- FallbackModeError =
Class.new(StandardError)
Instance Method Summary collapse
-
#initialize(args) ⇒ QueueAllocator
constructor
A new instance of QueueAllocator.
- #test_file_paths(can_initialize_queue, executed_test_files, batch_uuid: SecureRandom.uuid, time_tracker: nil) ⇒ Object
Constructor Details
#initialize(args) ⇒ QueueAllocator
Returns a new instance of QueueAllocator.
43 44 45 46 47 48 49 50 51 |
# File 'lib/knapsack_pro/queue_allocator.rb', line 43 def initialize(args) @test_suite = args.fetch(:test_suite) @ci_node_total = args.fetch(:ci_node_total) @ci_node_index = args.fetch(:ci_node_index) @repository_adapter = args.fetch(:repository_adapter) @fallback_mode = false @batch_index = -1 @batch_id = nil end |
Instance Method Details
#test_file_paths(can_initialize_queue, executed_test_files, batch_uuid: SecureRandom.uuid, time_tracker: nil) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/knapsack_pro/queue_allocator.rb', line 53 def test_file_paths(can_initialize_queue, executed_test_files, batch_uuid: SecureRandom.uuid, time_tracker: nil) @batch_index += 1 return [] if @fallback_mode batch = pull_tests_from_queue(can_initialize_queue, batch_uuid, time_tracker: time_tracker) return switch_to_fallback_mode(executed_test_files: executed_test_files) if batch.connection_failed? return normalize_test_files(batch.test_files) if batch.queue_exists? test_files_result = test_suite.calculate_test_files return try_initializing_queue(test_files_result.test_files, batch_uuid, time_tracker: time_tracker) if test_files_result.quick? # The tests to run were found slowly. By that time, the queue could have already been initialized by another CI node. # Attempt to pull tests from the queue to avoid the attempt to initialize the queue unnecessarily (queue initialization is an expensive request with a big test files payload). batch = pull_tests_from_queue(can_initialize_queue, batch_uuid, time_tracker: time_tracker) return switch_to_fallback_mode(executed_test_files: executed_test_files) if batch.connection_failed? return normalize_test_files(batch.test_files) if batch.queue_exists? try_initializing_queue(test_files_result.test_files, batch_uuid, time_tracker: time_tracker) end |