Skip to content

Commit

Permalink
Cache the bash_output path
Browse files Browse the repository at this point in the history
re-creating the path is the most expensive thing after actually running
the commands
  • Loading branch information
mvidner committed Sep 1, 2017
1 parent 868b273 commit bda132b
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion library/systemd/src/lib/yast2/systemctl.rb
Expand Up @@ -24,14 +24,16 @@ module Systemctl
TIMEOUT = 30 # seconds

class << self
BASH_SCR_PATH = Yast::Path.new(".target.bash_output")

# @param command [String]
# @return [#command,#stdout,#stderr,#exit]
# @raise [SystemctlError] if it times out
def execute(command)
log.info("systemctl #{command}")
command = SYSTEMCTL + command
log.debug "Executing `systemctl` command: #{command}"
result = timeout(TIMEOUT) { SCR.Execute(Path.new(".target.bash_output"), command) }
result = timeout(TIMEOUT) { SCR.Execute(BASH_SCR_PATH, command) }
OpenStruct.new(result.merge!(command: command))
rescue Timeout::Error
raise SystemctlError, "Timeout #{TIMEOUT} seconds: #{command}"
Expand Down

0 comments on commit bda132b

Please sign in to comment.