Class: Toolshed::Base
- Inherits:
-
Object
- Object
- Toolshed::Base
- Defined in:
- lib/toolshed/base.rb
Overview
Base class for toolshed responsible for methods used all over.
Direct Known Subclasses
Class Method Summary collapse
-
.wait_for_command(command, seconds = 10) ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/LineLength.
Instance Method Summary collapse
-
#initialize ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
7 8 |
# File 'lib/toolshed/base.rb', line 7 def initialize end |
Class Method Details
.wait_for_command(command, seconds = 10) ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/LineLength
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# 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 |