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

Methods

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.

Public Instance methods

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 79
79:       def current_task
80:         return nil if task_call_frames.empty?
81:         task_call_frames.last.task
82:       end

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 79
79:       def current_task
80:         return nil if task_call_frames.empty?
81:         task_call_frames.last.task
82:       end

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

[Source]

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

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

[Source]

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

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 97
 97:       def find_and_execute_task(path, hooks={})
 98:         task = find_task(path) or raise NoSuchTaskError, "the task `#{path}' does not exist"
 99: 
100:         trigger(hooks[:before], task) if hooks[:before]
101:         result = execute_task(task)
102:         trigger(hooks[:after], task) if hooks[:after]
103: 
104:         result
105:       end

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 97
 97:       def find_and_execute_task(path, hooks={})
 98:         task = find_task(path) or raise NoSuchTaskError, "the task `#{path}' does not exist"
 99: 
100:         trigger(hooks[:before], task) if hooks[:before]
101:         result = execute_task(task)
102:         trigger(hooks[:after], task) if hooks[:after]
103: 
104:         result
105:       end

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 69
69:       def on_rollback(&block)
70:         if transaction?
71:           # don't note a new rollback request if one has already been set
72:           rollback_requests << task_call_frames.last unless task_call_frames.last.rollback
73:           task_call_frames.last.rollback = block
74:         end
75:       end

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 69
69:       def on_rollback(&block)
70:         if transaction?
71:           # don't note a new rollback request if one has already been set
72:           rollback_requests << task_call_frames.last unless task_call_frames.last.rollback
73:           task_call_frames.last.rollback = block
74:         end
75:       end

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.

[Source]

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

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.

[Source]

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

[Source]

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

[Source]

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

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.

[Source]

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

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.

[Source]

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

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 47
47:       def transaction
48:         raise ArgumentError, "expected a block" unless block_given?
49:         raise ScriptError, "transaction must be called from within a task" if task_call_frames.empty?
50: 
51:         return yield if transaction?
52: 
53:         logger.info "transaction: start"
54:         begin
55:           self.rollback_requests = []
56:           yield
57:           logger.info "transaction: commit"
58:         rescue Object => e
59:           rollback!
60:           raise
61:         ensure
62:           self.rollback_requests = nil if Thread.main == Thread.current
63:         end
64:       end

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 47
47:       def transaction
48:         raise ArgumentError, "expected a block" unless block_given?
49:         raise ScriptError, "transaction must be called from within a task" if task_call_frames.empty?
50: 
51:         return yield if transaction?
52: 
53:         logger.info "transaction: start"
54:         begin
55:           self.rollback_requests = []
56:           yield
57:           logger.info "transaction: commit"
58:         rescue Object => e
59:           rollback!
60:           raise
61:         ensure
62:           self.rollback_requests = nil if Thread.main == Thread.current
63:         end
64:       end

Returns true if there is a transaction currently active.

[Source]

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

Returns true if there is a transaction currently active.

[Source]

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

Protected Instance methods

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

[Source]

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

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

[Source]

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

[Source]

     # File lib/capistrano/configuration/execution.rb, line 133
133:       def pop_task_call_frame
134:         task_call_frames.pop
135:       end

[Source]

     # File lib/capistrano/configuration/execution.rb, line 133
133:       def pop_task_call_frame
134:         task_call_frames.pop
135:       end

[Source]

     # File lib/capistrano/configuration/execution.rb, line 128
128:       def push_task_call_frame(task)
129:         frame = TaskCallFrame.new(task)
130:         task_call_frames.push frame
131:       end

[Source]

     # File lib/capistrano/configuration/execution.rb, line 128
128:       def push_task_call_frame(task)
129:         frame = TaskCallFrame.new(task)
130:         task_call_frames.push frame
131:       end

[Source]

     # File lib/capistrano/configuration/execution.rb, line 109
109:       def rollback!
110:         return if Thread.current[:rollback_requests].nil?
111:         Thread.current[:rolled_back] = true
112:    
113:         # throw the task back on the stack so that roles are properly
114:         # interpreted in the scope of the task in question.
115:         rollback_requests.reverse.each do |frame|
116:           begin
117:             push_task_call_frame(frame.task)
118:             logger.important "rolling back", frame.task.fully_qualified_name
119:             frame.rollback.call
120:           rescue Object => e
121:             logger.info "exception while rolling back: #{e.class}, #{e.message}", frame.task.fully_qualified_name
122:           ensure
123:             pop_task_call_frame
124:           end
125:         end
126:       end

[Source]

     # File lib/capistrano/configuration/execution.rb, line 109
109:       def rollback!
110:         return if Thread.current[:rollback_requests].nil?
111:         Thread.current[:rolled_back] = true
112:    
113:         # throw the task back on the stack so that roles are properly
114:         # interpreted in the scope of the task in question.
115:         rollback_requests.reverse.each do |frame|
116:           begin
117:             push_task_call_frame(frame.task)
118:             logger.important "rolling back", frame.task.fully_qualified_name
119:             frame.rollback.call
120:           rescue Object => e
121:             logger.info "exception while rolling back: #{e.class}, #{e.message}", frame.task.fully_qualified_name
122:           ensure
123:             pop_task_call_frame
124:           end
125:         end
126:       end

[Validate]