This class encapsulates a single command to be executed on a set of remote machines, in parallel.
Instantiates a new command object. The command must be a string containing the command to execute. sessions is an array of Net::SSH session instances, and options must be a hash containing any of the following keys:
logger: (optional), a Capistrano::Logger instance
data: (optional), a string to be sent to the command via it's stdin
env: (optional), a string or hash to be interpreted as environment variables that should be defined for this command invocation.
# File lib/capistrano/command.rb, line 146 def initialize(tree, sessions, options={}, &block) if String === tree tree = Tree.new(nil) { |t| t.else(tree, &block) } elsif block raise ArgumentError, "block given with tree argument" end @tree = tree @sessions = sessions @options = options @channels = open_channels end
Processes the command in parallel on all specified hosts. If the command fails (non-zero return code) on any of the hosts, this will raise a Capistrano::CommandError.
# File lib/capistrano/command.rb, line 162 def process! elapsed = Benchmark.realtime do loop do break unless process_iteration { @channels.any? { |ch| !ch[:closed] } } end end logger.trace "command finished in #{(elapsed * 1000).round}ms" if logger if (failed = @channels.select { |ch| ch[:status] != 0 }).any? commands = failed.inject({}) { |map, ch| (map[ch[:command]] ||= []) << ch[:server]; map } message = commands.map { |command, list| "#{command.inspect} on #{list.join(',')}" }.join("; ") error = CommandError.new("failed: #{message}") error.hosts = commands.values.flatten raise error end self end
Generated with the Darkfish Rdoc Generator 2.