Sha256: d3e053e4ca47c75482465d9673ed96ce306b64127de11b182023d8e7f5a8a66e

Contents?: true

Size: 1.53 KB

Versions: 5

Compression:

Stored size: 1.53 KB

Contents

module KnapsackPro
  module Runners
    module Queue
      class BaseRunner
        TERMINATION_SIGNALS = %w(HUP INT TERM ABRT QUIT USR1 USR2)

        @@terminate_process = false

        def self.run(args)
          raise NotImplementedError
        end

        def self.run_tests(runner, can_initialize_queue, args, exitstatus)
          raise NotImplementedError
        end

        def initialize(adapter_class)
          @allocator_builder = KnapsackPro::QueueAllocatorBuilder.new(adapter_class)
          @allocator = allocator_builder.allocator
          trap_signals
        end

        def test_file_paths(args)
          can_initialize_queue = args.fetch(:can_initialize_queue)
          executed_test_files = args.fetch(:executed_test_files)
          allocator.test_file_paths(can_initialize_queue, executed_test_files)
        end

        def test_dir
          allocator_builder.test_dir
        end

        private

        attr_reader :allocator_builder,
          :allocator

        def self.child_status
          $?
        end

        def self.handle_signal!
          raise 'Knapsack Pro process was terminated!' if @@terminate_process
        end

        def self.set_terminate_process
          @@terminate_process = true
        end

        def trap_signals
          TERMINATION_SIGNALS.each do |signal|
            Signal.trap(signal) {
              puts "#{signal} signal has been received. Terminating Knapsack Pro..."
              @@terminate_process = true
            }
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
knapsack_pro-5.5.0 lib/knapsack_pro/runners/queue/base_runner.rb
knapsack_pro-5.4.1 lib/knapsack_pro/runners/queue/base_runner.rb
knapsack_pro-5.4.0 lib/knapsack_pro/runners/queue/base_runner.rb
knapsack_pro-5.3.5 lib/knapsack_pro/runners/queue/base_runner.rb
knapsack_pro-5.3.4 lib/knapsack_pro/runners/queue/base_runner.rb