Class | Capistrano::Command |
In: |
lib/capistrano/command.rb
lib/capistrano/command.rb |
Parent: | Object |
This class encapsulates a single command to be executed on a set of remote machines, in parallel.
options | [R] | |
options | [R] | |
sessions | [R] | |
sessions | [R] | |
tree | [R] | |
tree | [R] |
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:
# File lib/capistrano/command.rb, line 145 145: def initialize(tree, sessions, options={}, &block) 146: if String === tree 147: tree = Tree.new(nil) { |t| t.else(tree, &block) } 148: elsif block 149: raise ArgumentError, "block given with tree argument" 150: end 151: 152: @tree = tree 153: @sessions = sessions 154: @options = options 155: @channels = open_channels 156: end
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:
# File lib/capistrano/command.rb, line 145 145: def initialize(tree, sessions, options={}, &block) 146: if String === tree 147: tree = Tree.new(nil) { |t| t.else(tree, &block) } 148: elsif block 149: raise ArgumentError, "block given with tree argument" 150: end 151: 152: @tree = tree 153: @sessions = sessions 154: @options = options 155: @channels = open_channels 156: end
# File lib/capistrano/command.rb, line 132 132: def self.process(tree, sessions, options={}) 133: new(tree, sessions, options).process! 134: end
# File lib/capistrano/command.rb, line 132 132: def self.process(tree, sessions, options={}) 133: new(tree, sessions, options).process! 134: 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 161 161: def process! 162: loop do 163: break unless process_iteration { @channels.any? { |ch| !ch[:closed] } } 164: end 165: 166: logger.trace "command finished" if logger 167: 168: if (failed = @channels.select { |ch| ch[:status] != 0 }).any? 169: commands = failed.inject({}) { |map, ch| (map[ch[:command]] ||= []) << ch[:server]; map } 170: message = commands.map { |command, list| "#{command.inspect} on #{list.join(',')}" }.join("; ") 171: error = CommandError.new("failed: #{message}") 172: error.hosts = commands.values.flatten 173: raise error 174: end 175: 176: self 177: 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 161 161: def process! 162: loop do 163: break unless process_iteration { @channels.any? { |ch| !ch[:closed] } } 164: end 165: 166: logger.trace "command finished" if logger 167: 168: if (failed = @channels.select { |ch| ch[:status] != 0 }).any? 169: commands = failed.inject({}) { |map, ch| (map[ch[:command]] ||= []) << ch[:server]; map } 170: message = commands.map { |command, list| "#{command.inspect} on #{list.join(',')}" }.join("; ") 171: error = CommandError.new("failed: #{message}") 172: error.hosts = commands.values.flatten 173: raise error 174: end 175: 176: self 177: end