class Instrumentality::Executor
Public Class Methods
execute(cmd, verbose = false)
click to toggle source
# File lib/instrumentality/executor.rb, line 10 def self.execute(cmd, verbose = false) Logger.log("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)
click to toggle source
# File lib/instrumentality/executor.rb, line 21 def self.execute_async(cmd) Process.spawn("#{cmd}").tap do |pid| Logger.log("Spawned process (PID: #{pid}) from command: #{cmd}") end end
timeout(process, seconds = Constants::TIMEOUT)
click to toggle source
# File lib/instrumentality/executor.rb, line 27 def self.timeout(process, seconds = Constants::TIMEOUT) pid = "" begin Timeout.timeout(seconds) do loop do pid = `ps aux | grep #{process}.app | grep -v grep | awk '{print $2}'`.strip break if pid != "" end end rescue Timeout::Error raise ExecutorError, "Timeout while trying to find #{process} process".red end pid.tap do |pid| Logger.log("Found process #{process} with PID: #{pid}") end end