forked from newrelic/centurion
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
These methods should never have been in logging.
- Loading branch information
Showing
5 changed files
with
62 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
module Centurion; end | ||
|
||
module Centurion::Shell | ||
def self.echo(command) | ||
if Thread.list.find_all { |t| t.status == 'run' }.count > 1 | ||
run_without_echo(command) | ||
else | ||
run_with_echo(command) | ||
end | ||
end | ||
|
||
def self.run_without_echo(command) | ||
output = Queue.new | ||
output_thread = Thread.new do | ||
while true do | ||
begin | ||
puts output.pop | ||
rescue => e | ||
info "Rescuing... #{e.message}" | ||
end | ||
end | ||
end | ||
|
||
IO.popen(command) do |io| | ||
io.each_line { |line| output << line } | ||
end | ||
|
||
output_thread.kill | ||
validate_status(command) | ||
end | ||
|
||
def self.run_with_echo(command) | ||
$stdout.sync = true | ||
$stderr.sync = true | ||
IO.popen(command) do |io| | ||
io.each_char { |char| print char } | ||
end | ||
validate_status(command) | ||
end | ||
|
||
def self.validate_status(command) | ||
unless $?.success? | ||
raise "The command failed with a non-zero exit status: #{$?.exitstatus}. Command: '#{command}'" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters