Module: Capistrano::Configuration::Execution

### Home Classes Methods

### In Files

- lib/capistrano/configuration/execution.rb

### Methods

- #current_task
- #execute_task
- #find_and_execute_task
- #invoke_task_directly
- #on_rollback
- #pop_task_call_frame
- #push_task_call_frame
- #rollback!
- #rollback_requests
- #rollback_requests=
- #task_call_frames
- #transaction
- #transaction?

### Files

- help.txt

### Class/Module Index

Quicksearch

- Capistrano
- Capistrano::CLI
- Capistrano::CLI::Execute
- Capistrano::CLI::Execute::ClassMethods
- Capistrano::CLI::Help
- Capistrano::CLI::Options
- Capistrano::CLI::Options::ClassMethods
- Capistrano::CLI::UI
- Capistrano::CLI::UI::ClassMethods
- Capistrano::Callback
- Capistrano::Command
- Capistrano::Command::Tree
- Capistrano::Command::Tree::Branch
- Capistrano::Command::Tree::ConditionBranch
- Capistrano::Command::Tree::ConditionBranch::Evaluator
- Capistrano::Command::Tree::ElseBranch
- Capistrano::Configuration
- Capistrano::Configuration::Actions
- Capistrano::Configuration::Actions::FileTransfer
- Capistrano::Configuration::Actions::Inspect
- Capistrano::Configuration::Actions::Invocation
- Capistrano::Configuration::Actions::Invocation::ClassMethods
- Capistrano::Configuration::AliasTask
- Capistrano::Configuration::Callbacks
- Capistrano::Configuration::Connections
- Capistrano::Configuration::Execution
- Capistrano::Configuration::Loading
- Capistrano::Configuration::Loading::ClassMethods
- Capistrano::Configuration::LogFormatters
- Capistrano::Configuration::Namespaces
- Capistrano::Configuration::Namespaces::Namespace
- Capistrano::Configuration::Roles
- Capistrano::Configuration::Servers
- Capistrano::Configuration::Variables
- Capistrano::Deploy
- Capistrano::Deploy::Dependencies
- Capistrano::Deploy::LocalDependency
- Capistrano::Deploy::RemoteDependency
- Capistrano::Deploy::SCM
- Capistrano::Deploy::SCM::Accurev
- Capistrano::Deploy::SCM::Accurev::InternalRevision
- Capistrano::Deploy::SCM::Base
- Capistrano::Deploy::SCM::Base::LocalProxy
- Capistrano::Deploy::SCM::Bzr
- Capistrano::Deploy::SCM::Cvs
- Capistrano::Deploy::SCM::Darcs
- Capistrano::Deploy::SCM::Git
- Capistrano::Deploy::SCM::Mercurial
- Capistrano::Deploy::SCM::None
- Capistrano::Deploy::SCM::Perforce
- Capistrano::Deploy::SCM::Subversion
- Capistrano::Deploy::Strategy
- Capistrano::Deploy::Strategy::Base
- Capistrano::Deploy::Strategy::Checkout
- Capistrano::Deploy::Strategy::Copy
- Capistrano::Deploy::Strategy::Export
- Capistrano::Deploy::Strategy::Remote
- Capistrano::Deploy::Strategy::RemoteCache
- Capistrano::Deploy::Strategy::UnsharedRemoteCache
- Capistrano::ProcCallback
- Capistrano::Processable
- Capistrano::Processable::SessionAssociation
- Capistrano::RemoteError
- Capistrano::Role
- Capistrano::Role::DynamicServerList
- Capistrano::SSH
- Capistrano::ServerDefinition
- Capistrano::Shell
- Capistrano::TaskCallback
- Capistrano::TaskDefinition
- Capistrano::Transfer
- Capistrano::Transfer::SFTPTransferWrapper
- Capistrano::Version
- Kernel
- Object
- String

No matching classes.

# Capistrano::Configuration::Execution

### Constants

TaskCallFrame

  A struct for representing a single instance of an invoked task.

### Public Instance Methods

current_task() click to toggle source

Returns the TaskDefinition object for the currently executing task. It returns nil if there is no task being executed.

    # File lib/capistrano/configuration/execution.rb, line 79
    def current_task
      return nil if task_call_frames.empty?
      task_call_frames.last.task
    end

execute_task(task) click to toggle source

Executes the task with the given name, without invoking any associated callbacks.

    # File lib/capistrano/configuration/execution.rb, line 86
    def execute_task(task)
      logger.debug "executing `#{task.fully_qualified_name}'"
      push_task_call_frame(task)
      invoke_task_directly(task)
    ensure
      pop_task_call_frame
    end

find_and_execute_task(path, hooks={}) click to toggle source

Attempts to locate the task at the given fully-qualified path, and execute it. If no such task exists, a Capistrano::NoSuchTaskError will be raised.

    # File lib/capistrano/configuration/execution.rb, line 97
    def find_and_execute_task(path, hooks={})
      task = find_task(path) or raise NoSuchTaskError, "the task `#{path}' does not exist"

      trigger(hooks[:before], task) if hooks[:before]
      result = execute_task(task)
      trigger(hooks[:after], task) if hooks[:after]

      result
    end

on_rollback(&block) click to toggle source

Specifies an on_rollback hook for the currently executing task. If this or any subsequent task then fails, and a transaction is active, this hook will be executed.

    # File lib/capistrano/configuration/execution.rb, line 69
    def on_rollback(&block)
      if transaction?
        # don't note a new rollback request if one has already been set
        rollback_requests << task_call_frames.last unless task_call_frames.last.rollback
        task_call_frames.last.rollback = block
      end
    end

rollback_requests() click to toggle source

The stack of tasks that have registered rollback handlers within the current transaction. If this is nil, then there is no transaction that is currently active.

    # File lib/capistrano/configuration/execution.rb, line 35
    def rollback_requests
      Thread.current[:rollback_requests]
    end

rollback_requests=(rollback_requests) click to toggle source

    # File lib/capistrano/configuration/execution.rb, line 39
    def rollback_requests=(rollback_requests)
      Thread.current[:rollback_requests] = rollback_requests
    end

task_call_frames() click to toggle source

The call stack of the tasks. The currently executing task may inspect this to see who its caller was. The current task is always the last element of this stack.

    # File lib/capistrano/configuration/execution.rb, line 27
    def task_call_frames
      Thread.current[:task_call_frames] ||= []
    end

transaction() click to toggle source

Invoke a set of tasks in a transaction. If any task fails (raises an exception), all tasks executed within the transaction are inspected to see if they have an associated on_rollback hook, and if so, that hook is called.

    # File lib/capistrano/configuration/execution.rb, line 47
    def transaction
      raise ArgumentError, "expected a block" unless block_given?
      raise ScriptError, "transaction must be called from within a task" if task_call_frames.empty?

      return yield if transaction?

      logger.info "transaction: start"
      begin
        self.rollback_requests = []
        yield
        logger.info "transaction: commit"
      rescue Object => e
        rollback!
        raise
      ensure
        self.rollback_requests = nil
      end
    end

transaction?() click to toggle source

Returns true if there is a transaction currently active.

    # File lib/capistrano/configuration/execution.rb, line 20
    def transaction?
      !rollback_requests.nil?
    end

### Protected Instance Methods

invoke_task_directly(task) click to toggle source

Invokes the task's body directly, without setting up the call frame.

    # File lib/capistrano/configuration/execution.rb, line 137
    def invoke_task_directly(task)
      task.namespace.instance_eval(&task.body)
    end

pop_task_call_frame() click to toggle source

    # File lib/capistrano/configuration/execution.rb, line 132
    def pop_task_call_frame
      task_call_frames.pop
    end

push_task_call_frame(task) click to toggle source

    # File lib/capistrano/configuration/execution.rb, line 127
    def push_task_call_frame(task)
      frame = TaskCallFrame.new(task)
      task_call_frames.push frame
    end

rollback!() click to toggle source

    # File lib/capistrano/configuration/execution.rb, line 109
    def rollback!
      return if Thread.current[:rollback_requests].nil?

      # throw the task back on the stack so that roles are properly
      # interpreted in the scope of the task in question.
      rollback_requests.reverse.each do |frame|
        begin
          push_task_call_frame(frame.task)
          logger.important "rolling back", frame.task.fully_qualified_name
          frame.rollback.call
        rescue Object => e
          logger.info "exception while rolling back: #{e.class}, #{e.message}", frame.task.fully_qualified_name
        ensure
          pop_task_call_frame
        end
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.