class Toolshed::Base

Base class for toolshed responsible for methods used all over.

Public Class Methods

new() click to toggle source
# File lib/toolshed/base.rb, line 7
def initialize
end
wait_for_command(command, seconds = 10) click to toggle source
# File lib/toolshed/base.rb, line 10
def self.wait_for_command(command, seconds = 10) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/LineLength
  result = {}
  Open3.popen3(command) do |stdin, stdout, stderr, wait_thr|
    begin
      ::Timeout.timeout(seconds) do
        stdin.close  # make sure the subprocess is done

        a_stdout = []
        while line = stdout.gets
          a_stdout << line
        end
        a_stderr = []
        while line = stderr.gets
          a_stderr << line
        end

        all = a_stdout + a_stderr
        exit_status = wait_thr.value.to_s # Process::Status object returned.
        result.merge!(stdout: a_stdout, stderr: a_stderr, all: all, process_status: exit_status) # rubocop:disable Metrics/LineLength
      end
    rescue ::Timeout::Error
      Process.kill('KILL', wait_thr.pid)
      Toolshed.logger.fatal "Unable to perform the '#{command}' command in the allowed amount of time of #{seconds} seconds. Exiting." # rubocop:disable Metrics/LineLength
      Toolshed.die
    end
  end
  result
end