Parent

Namespace

Included Modules

Files

Class/Module Index [+]

Quicksearch

Capistrano::Command

This class encapsulates a single command to be executed on a set of remote machines, in parallel.

Attributes

options[R]
sessions[R]
tree[R]

Public Class Methods

new(tree, sessions, options={}, &block) click to toggle source

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
process(tree, sessions, options={}) click to toggle source
# File lib/capistrano/command.rb, line 133
def self.process(tree, sessions, options={})
  new(tree, sessions, options).process!
end

Public Instance Methods

process!() click to toggle source

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
stop!() click to toggle source

Force the command to stop processing, by closing all open channels associated with this command.

# File lib/capistrano/command.rb, line 184
def stop!
  @channels.each do |ch|
    ch.close unless ch[:closed]
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.