Module: Capistrano::Configuration::Execution

Module | Capistrano::Configuration::Execution
In: | lib/capistrano/configuration/execution.rb lib/capistrano/configuration/execution.rb

### Methods

current_task current_task execute_task execute_task find_and_execute_task find_and_execute_task invoke_task_directly invoke_task_directly on_rollback on_rollback pop_task_call_frame pop_task_call_frame push_task_call_frame push_task_call_frame rollback! rollback! transaction transaction transaction? transaction?

### Constants

TaskCallFrame | = | Struct.new(:task, :rollback) |  | A struct for representing a single instance of an invoked task.
TaskCallFrame | = | Struct.new(:task, :rollback) |  | A struct for representing a single instance of an invoked task.

### Attributes

rollback_requests | [R] | 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.
rollback_requests | [R] | 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.
task_call_frames | [R] | 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.
task_call_frames | [R] | 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.

### Public Instance methods

current_task()

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

[Source]

        # File lib/capistrano/configuration/execution.rb, line 71
    71:       def current_task
    72:         return nil if task_call_frames.empty?
    73:         task_call_frames.last.task
    74:       end

current_task()

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

[Source]

        # File lib/capistrano/configuration/execution.rb, line 71
    71:       def current_task
    72:         return nil if task_call_frames.empty?
    73:         task_call_frames.last.task
    74:       end

execute_task(task)

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

[Source]

        # File lib/capistrano/configuration/execution.rb, line 78
    78:       def execute_task(task)
    79:         logger.debug "executing `#{task.fully_qualified_name}'"
    80:         push_task_call_frame(task)
    81:         invoke_task_directly(task)
    82:       ensure
    83:         pop_task_call_frame
    84:       end

execute_task(task)

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

[Source]

        # File lib/capistrano/configuration/execution.rb, line 78
    78:       def execute_task(task)
    79:         logger.debug "executing `#{task.fully_qualified_name}'"
    80:         push_task_call_frame(task)
    81:         invoke_task_directly(task)
    82:       ensure
    83:         pop_task_call_frame
    84:       end

find_and_execute_task(path, hooks={})

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.

[Source]

        # File lib/capistrano/configuration/execution.rb, line 89
    89:       def find_and_execute_task(path, hooks={})
    90:         task = find_task(path) or raise NoSuchTaskError, "the task `#{path}' does not exist"
    91:
    92:         trigger(hooks[:before], task) if hooks[:before]
    93:         result = execute_task(task)
    94:         trigger(hooks[:after], task) if hooks[:after]
    95:
    96:         result
    97:       end

find_and_execute_task(path, hooks={})

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.

[Source]

        # File lib/capistrano/configuration/execution.rb, line 89
    89:       def find_and_execute_task(path, hooks={})
    90:         task = find_task(path) or raise NoSuchTaskError, "the task `#{path}' does not exist"
    91:
    92:         trigger(hooks[:before], task) if hooks[:before]
    93:         result = execute_task(task)
    94:         trigger(hooks[:after], task) if hooks[:after]
    95:
    96:         result
    97:       end

on_rollback(&block)

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.

[Source]

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

on_rollback(&block)

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.

[Source]

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

transaction() {|if transaction?| ...}

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.

[Source]

        # File lib/capistrano/configuration/execution.rb, line 39
    39:       def transaction
    40:         raise ArgumentError, "expected a block" unless block_given?
    41:         raise ScriptError, "transaction must be called from within a task" if task_call_frames.empty?
    42:
    43:         return yield if transaction?
    44:
    45:         logger.info "transaction: start"
    46:         begin
    47:           @rollback_requests = []
    48:           yield
    49:           logger.info "transaction: commit"
    50:         rescue Object => e
    51:           rollback!
    52:           raise
    53:         ensure
    54:           @rollback_requests = nil
    55:         end
    56:       end

transaction() {|if transaction?| ...}

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.

[Source]

        # File lib/capistrano/configuration/execution.rb, line 39
    39:       def transaction
    40:         raise ArgumentError, "expected a block" unless block_given?
    41:         raise ScriptError, "transaction must be called from within a task" if task_call_frames.empty?
    42:
    43:         return yield if transaction?
    44:
    45:         logger.info "transaction: start"
    46:         begin
    47:           @rollback_requests = []
    48:           yield
    49:           logger.info "transaction: commit"
    50:         rescue Object => e
    51:           rollback!
    52:           raise
    53:         ensure
    54:           @rollback_requests = nil
    55:         end
    56:       end

transaction?()

Returns true if there is a transaction currently active.

[Source]

        # File lib/capistrano/configuration/execution.rb, line 31
    31:       def transaction?
    32:         !rollback_requests.nil?
    33:       end

transaction?()

Returns true if there is a transaction currently active.

[Source]

        # File lib/capistrano/configuration/execution.rb, line 31
    31:       def transaction?
    32:         !rollback_requests.nil?
    33:       end

### Protected Instance methods

invoke_task_directly(task)

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

[Source]

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

invoke_task_directly(task)

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

[Source]

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

pop_task_call_frame()

[Source]

         # File lib/capistrano/configuration/execution.rb, line 122
    122:       def pop_task_call_frame
    123:         task_call_frames.pop
    124:       end

pop_task_call_frame()

[Source]

         # File lib/capistrano/configuration/execution.rb, line 122
    122:       def pop_task_call_frame
    123:         task_call_frames.pop
    124:       end

push_task_call_frame(task)

[Source]

         # File lib/capistrano/configuration/execution.rb, line 117
    117:       def push_task_call_frame(task)
    118:         frame = TaskCallFrame.new(task)
    119:         task_call_frames.push frame
    120:       end

push_task_call_frame(task)

[Source]

         # File lib/capistrano/configuration/execution.rb, line 117
    117:       def push_task_call_frame(task)
    118:         frame = TaskCallFrame.new(task)
    119:         task_call_frames.push frame
    120:       end

rollback!()

[Source]

         # File lib/capistrano/configuration/execution.rb, line 101
    101:       def rollback!
    102:         # throw the task back on the stack so that roles are properly
    103:         # interpreted in the scope of the task in question.
    104:         rollback_requests.reverse.each do |frame|
    105:           begin
    106:             push_task_call_frame(frame.task)
    107:             logger.important "rolling back", frame.task.fully_qualified_name
    108:             frame.rollback.call
    109:           rescue Object => e
    110:             logger.info "exception while rolling back: #{e.class}, #{e.message}", frame.task.fully_qualified_name
    111:           ensure
    112:             pop_task_call_frame
    113:           end
    114:         end
    115:       end

rollback!()

[Source]

         # File lib/capistrano/configuration/execution.rb, line 101
    101:       def rollback!
    102:         # throw the task back on the stack so that roles are properly
    103:         # interpreted in the scope of the task in question.
    104:         rollback_requests.reverse.each do |frame|
    105:           begin
    106:             push_task_call_frame(frame.task)
    107:             logger.important "rolling back", frame.task.fully_qualified_name
    108:             frame.rollback.call
    109:           rescue Object => e
    110:             logger.info "exception while rolling back: #{e.class}, #{e.message}", frame.task.fully_qualified_name
    111:           ensure
    112:             pop_task_call_frame
    113:           end
    114:         end
    115:       end

[Validate]