class Proxy::DiscoveryImage::PowerApi

Public Instance Methods

run_after_response(seconds, *command) click to toggle source

Execute command in a separate thread after 5 seconds to give the server some time to finish the request. Does not execute via a shell.

# File lib/smart_proxy_discovery_image/power_api.rb, line 42
def run_after_response(seconds, *command)
  logger.debug "Power API scheduling in #{seconds} seconds: #{command.inspect}"
  Thread.start do
    begin
      sleep seconds
      logger.debug "Power API executing: #{command.inspect}"
      if (sudo = which('sudo'))
        status = system(sudo, *command)
      else
        logger.warn "sudo binary was not found"
      end
      # only report errors
      logger.warn "The attempted command failed with code #{$?.exitstatus}" unless status
    rescue Exception => e
      logger.error "Error during command execution: #{e}"
    end
  end
end