Class: Instrumentality::Executor
- Inherits:
-
Object
- Object
- Instrumentality::Executor
- Defined in:
- lib/instrumentality/executor.rb
Defined Under Namespace
Classes: ExecutorError
Class Method Summary collapse
- .execute(cmd, verbose = false) ⇒ Object
- .execute_async(cmd) ⇒ Object
- .timeout(process, seconds = Constants::TIMEOUT) ⇒ Object
Class Method Details
.execute(cmd, verbose = false) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/instrumentality/executor.rb', line 10 def self.execute(cmd, verbose = false) puts "#{Constants::OUTPUT_PREFIX} Executing command: #{cmd}" if verbose system(cmd) else `#{cmd}` end status = $?.exitstatus raise ExecutorError, "Previous command execution failed with status: #{status}".red if status != 0 end |
.execute_async(cmd) ⇒ Object
21 22 23 24 25 |
# File 'lib/instrumentality/executor.rb', line 21 def self.execute_async(cmd) spawn("#{cmd}").tap do |pid| puts "#{Constants::OUTPUT_PREFIX} Spawned process (PID: #{pid}) from command: #{cmd}" end end |
.timeout(process, seconds = Constants::TIMEOUT) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/instrumentality/executor.rb', line 27 def self.timeout(process, seconds = Constants::TIMEOUT) pid = "" Timeout.timeout(seconds) do loop do pid = `ps aux | grep #{process}.app | grep -v grep | awk '{print $2}'`.strip break if pid != "" end end pid.tap do |pid| puts "#{Constants::OUTPUT_PREFIX} Found process #{process} with PID: #{pid}" end end |