Module | Capistrano::Configuration::Execution |
In: |
lib/capistrano/configuration/execution.rb
lib/capistrano/configuration/execution.rb |
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. |
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. |
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 70 70: def current_task 71: return nil if task_call_frames.empty? 72: task_call_frames.last.task 73: end
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 70 70: def current_task 71: return nil if task_call_frames.empty? 72: task_call_frames.last.task 73: end
Executes the task with the given name, without invoking any associated callbacks.
# File lib/capistrano/configuration/execution.rb, line 77 77: def execute_task(task) 78: logger.debug "executing `#{task.fully_qualified_name}'" 79: push_task_call_frame(task) 80: invoke_task_directly(task) 81: ensure 82: pop_task_call_frame 83: end
Executes the task with the given name, without invoking any associated callbacks.
# File lib/capistrano/configuration/execution.rb, line 77 77: def execute_task(task) 78: logger.debug "executing `#{task.fully_qualified_name}'" 79: push_task_call_frame(task) 80: invoke_task_directly(task) 81: ensure 82: pop_task_call_frame 83: 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.
# File lib/capistrano/configuration/execution.rb, line 88 88: def find_and_execute_task(path, hooks={}) 89: task = find_task(path) or raise NoSuchTaskError, "the task `#{path}' does not exist" 90: 91: trigger(hooks[:before], task) if hooks[:before] 92: result = execute_task(task) 93: trigger(hooks[:after], task) if hooks[:after] 94: 95: result 96: 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.
# File lib/capistrano/configuration/execution.rb, line 88 88: def find_and_execute_task(path, hooks={}) 89: task = find_task(path) or raise NoSuchTaskError, "the task `#{path}' does not exist" 90: 91: trigger(hooks[:before], task) if hooks[:before] 92: result = execute_task(task) 93: trigger(hooks[:after], task) if hooks[:after] 94: 95: result 96: 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.
# File lib/capistrano/configuration/execution.rb, line 61 61: def on_rollback(&block) 62: if transaction? 63: task_call_frames.last.rollback = block 64: rollback_requests << task_call_frames.last 65: end 66: 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.
# File lib/capistrano/configuration/execution.rb, line 61 61: def on_rollback(&block) 62: if transaction? 63: task_call_frames.last.rollback = block 64: rollback_requests << task_call_frames.last 65: end 66: 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.
# 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
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 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
Returns true if there is a transaction currently active.
# File lib/capistrano/configuration/execution.rb, line 31 31: def transaction? 32: !rollback_requests.nil? 33: end
Returns true if there is a transaction currently active.
# File lib/capistrano/configuration/execution.rb, line 31 31: def transaction? 32: !rollback_requests.nil? 33: end
Invokes the task‘s body directly, without setting up the call frame.
# File lib/capistrano/configuration/execution.rb, line 126 126: def invoke_task_directly(task) 127: task.namespace.instance_eval(&task.body) 128: end
Invokes the task‘s body directly, without setting up the call frame.
# File lib/capistrano/configuration/execution.rb, line 126 126: def invoke_task_directly(task) 127: task.namespace.instance_eval(&task.body) 128: end
# File lib/capistrano/configuration/execution.rb, line 121 121: def pop_task_call_frame 122: task_call_frames.pop 123: end
# File lib/capistrano/configuration/execution.rb, line 121 121: def pop_task_call_frame 122: task_call_frames.pop 123: end
# File lib/capistrano/configuration/execution.rb, line 116 116: def push_task_call_frame(task) 117: frame = TaskCallFrame.new(task) 118: task_call_frames.push frame 119: end
# File lib/capistrano/configuration/execution.rb, line 116 116: def push_task_call_frame(task) 117: frame = TaskCallFrame.new(task) 118: task_call_frames.push frame 119: end
# File lib/capistrano/configuration/execution.rb, line 100 100: def rollback! 101: # throw the task back on the stack so that roles are properly 102: # interpreted in the scope of the task in question. 103: rollback_requests.reverse.each do |frame| 104: begin 105: push_task_call_frame(frame.task) 106: logger.important "rolling back", frame.task.fully_qualified_name 107: frame.rollback.call 108: rescue Object => e 109: logger.info "exception while rolling back: #{e.class}, #{e.message}", frame.task.fully_qualified_name 110: ensure 111: pop_task_call_frame 112: end 113: end 114: end
# File lib/capistrano/configuration/execution.rb, line 100 100: def rollback! 101: # throw the task back on the stack so that roles are properly 102: # interpreted in the scope of the task in question. 103: rollback_requests.reverse.each do |frame| 104: begin 105: push_task_call_frame(frame.task) 106: logger.important "rolling back", frame.task.fully_qualified_name 107: frame.rollback.call 108: rescue Object => e 109: logger.info "exception while rolling back: #{e.class}, #{e.message}", frame.task.fully_qualified_name 110: ensure 111: pop_task_call_frame 112: end 113: end 114: end