mirror of
https://github.com/capistrano/capistrano
synced 2023-03-27 23:21:18 -04:00
Added elapsed time to remote and local command finished log messages
This commit is contained in:
parent
8b4015ea24
commit
20b168df06
3 changed files with 22 additions and 6 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
require 'benchmark'
|
||||||
require 'capistrano/errors'
|
require 'capistrano/errors'
|
||||||
require 'capistrano/processable'
|
require 'capistrano/processable'
|
||||||
|
|
||||||
|
@ -159,11 +160,13 @@ module Capistrano
|
||||||
# fails (non-zero return code) on any of the hosts, this will raise a
|
# fails (non-zero return code) on any of the hosts, this will raise a
|
||||||
# Capistrano::CommandError.
|
# Capistrano::CommandError.
|
||||||
def process!
|
def process!
|
||||||
loop do
|
elapsed = Benchmark.realtime do
|
||||||
break unless process_iteration { @channels.any? { |ch| !ch[:closed] } }
|
loop do
|
||||||
|
break unless process_iteration { @channels.any? { |ch| !ch[:closed] } }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
logger.trace "command finished" if logger
|
logger.trace "command finished in #{(elapsed * 1000).round}ms" if logger
|
||||||
|
|
||||||
if (failed = @channels.select { |ch| ch[:status] != 0 }).any?
|
if (failed = @channels.select { |ch| ch[:status] != 0 }).any?
|
||||||
commands = failed.inject({}) { |map, ch| (map[ch[:command]] ||= []) << ch[:server]; map }
|
commands = failed.inject({}) { |map, ch| (map[ch[:command]] ||= []) << ch[:server]; map }
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
require 'benchmark'
|
||||||
require 'yaml'
|
require 'yaml'
|
||||||
require 'capistrano/recipes/deploy/scm'
|
require 'capistrano/recipes/deploy/scm'
|
||||||
require 'capistrano/recipes/deploy/strategy'
|
require 'capistrano/recipes/deploy/strategy'
|
||||||
|
@ -95,10 +96,13 @@ end
|
||||||
# returns the command output as a string
|
# returns the command output as a string
|
||||||
def run_locally(cmd)
|
def run_locally(cmd)
|
||||||
logger.trace "executing locally: #{cmd.inspect}" if logger
|
logger.trace "executing locally: #{cmd.inspect}" if logger
|
||||||
output_on_stdout = `#{cmd}`
|
elapsed = Benchmark.realtime do
|
||||||
|
output_on_stdout = `#{cmd}`
|
||||||
|
end
|
||||||
if $?.to_i > 0 # $? is command exit code (posix style)
|
if $?.to_i > 0 # $? is command exit code (posix style)
|
||||||
raise Capistrano::LocalArgumentError, "Command #{cmd} returned status code #{$?}"
|
raise Capistrano::LocalArgumentError, "Command #{cmd} returned status code #{$?}"
|
||||||
end
|
end
|
||||||
|
logger.trace "command finished in #{(elapsed * 1000).round}ms" if logger
|
||||||
output_on_stdout
|
output_on_stdout
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
require 'benchmark'
|
||||||
require 'capistrano/recipes/deploy/dependencies'
|
require 'capistrano/recipes/deploy/dependencies'
|
||||||
|
|
||||||
module Capistrano
|
module Capistrano
|
||||||
|
@ -49,16 +50,24 @@ module Capistrano
|
||||||
# A wrapper for Kernel#system that logs the command being executed.
|
# A wrapper for Kernel#system that logs the command being executed.
|
||||||
def system(*args)
|
def system(*args)
|
||||||
cmd = args.join(' ')
|
cmd = args.join(' ')
|
||||||
|
result = nil
|
||||||
if RUBY_PLATFORM =~ /win32/
|
if RUBY_PLATFORM =~ /win32/
|
||||||
cmd = cmd.split(/\s+/).collect {|w| w.match(/^[\w+]+:\/\//) ? w : w.gsub('/', '\\') }.join(' ') # Split command by spaces, change / by \\ unless element is a some+thing://
|
cmd = cmd.split(/\s+/).collect {|w| w.match(/^[\w+]+:\/\//) ? w : w.gsub('/', '\\') }.join(' ') # Split command by spaces, change / by \\ unless element is a some+thing://
|
||||||
cmd.gsub!(/^cd /,'cd /D ') # Replace cd with cd /D
|
cmd.gsub!(/^cd /,'cd /D ') # Replace cd with cd /D
|
||||||
cmd.gsub!(/&& cd /,'&& cd /D ') # Replace cd with cd /D
|
cmd.gsub!(/&& cd /,'&& cd /D ') # Replace cd with cd /D
|
||||||
logger.trace "executing locally: #{cmd}"
|
logger.trace "executing locally: #{cmd}"
|
||||||
super(cmd)
|
elapsed = Benchmark.realtime do
|
||||||
|
result = super(cmd)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
logger.trace "executing locally: #{cmd}"
|
logger.trace "executing locally: #{cmd}"
|
||||||
super
|
elapsed = Benchmark.realtime do
|
||||||
|
result = super
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
logger.trace "command finished in #{(elapsed * 1000).round}ms"
|
||||||
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
Loading…
Reference in a new issue