Class: Capistrano::Command
- Inherits:
-
Object
- Object
- Capistrano::Command
- Defined in:
- lib/capistrano/command.rb
Overview
This class encapsulates a single command to be executed on a set of remote machines, in parallel.
Defined Under Namespace
Classes: Error
Instance Attribute Summary collapse
-
#actor ⇒ Object
readonly
Returns the value of attribute actor.
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#servers ⇒ Object
readonly
Returns the value of attribute servers.
Instance Method Summary collapse
-
#initialize(servers, command, callback, options, actor) ⇒ Command
constructor
:nodoc:.
-
#logger ⇒ Object
:nodoc:.
-
#process! ⇒ Object
Processes the command in parallel on all specified hosts.
-
#stop! ⇒ Object
Force the command to stop processing, by closing all open channels associated with this command.
Constructor Details
#initialize(servers, command, callback, options, actor) ⇒ Command
:nodoc:
10 11 12 13 14 15 16 17 |
# File 'lib/capistrano/command.rb', line 10 def initialize(servers, command, callback, , actor) #:nodoc: @servers = servers @command = extract_environment() + command.strip.gsub(/\r?\n/, "\\\n") @callback = callback @options = @actor = actor @channels = open_channels end |
Instance Attribute Details
#actor ⇒ Object (readonly)
Returns the value of attribute actor.
8 9 10 |
# File 'lib/capistrano/command.rb', line 8 def actor @actor end |
#command ⇒ Object (readonly)
Returns the value of attribute command.
8 9 10 |
# File 'lib/capistrano/command.rb', line 8 def command @command end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/capistrano/command.rb', line 8 def @options end |
#servers ⇒ Object (readonly)
Returns the value of attribute servers.
8 9 10 |
# File 'lib/capistrano/command.rb', line 8 def servers @servers end |
Instance Method Details
#logger ⇒ Object
:nodoc:
19 20 21 |
# File 'lib/capistrano/command.rb', line 19 def logger #:nodoc: actor.logger end |
#process! ⇒ Object
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 RuntimeError.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/capistrano/command.rb', line 26 def process! since = Time.now loop do active = 0 @channels.each do |ch| next if ch[:closed] active += 1 ch.connection.process(true) end break if active == 0 if Time.now - since >= 1 since = Time.now @channels.each { |ch| ch.connection.ping! } end sleep 0.01 # a brief respite, to keep the CPU from going crazy end logger.trace "command finished" if failed = @channels.detect { |ch| ch[:status] != 0 } raise Error, "command #{@command.inspect} failed on #{failed[:host]}" end self end |
#stop! ⇒ Object
Force the command to stop processing, by closing all open channels associated with this command.
55 56 57 58 59 |
# File 'lib/capistrano/command.rb', line 55 def stop! @channels.each do |ch| ch.close unless ch[:closed] end end |