Class: AvoDeploy::Task::TaskManager
- Inherits:
-
Object
- Object
- AvoDeploy::Task::TaskManager
- Defined in:
- lib/avodeploy/task/task_manager.rb
Instance Attribute Summary collapse
-
#chains ⇒ Object
readonly
Returns the value of attribute chains.
-
#dependencies ⇒ Object
readonly
Returns the value of attribute dependencies.
Instance Method Summary collapse
-
#add_task(name, options, &block) ⇒ Object
Adds a task to the task manager.
-
#execute_for_each_target(task, env) ⇒ Object
Executes a task for all defined targets.
-
#find_chain_index_containing(name) ⇒ Object
Finds the chain containing a specifc task.
-
#initialize ⇒ TaskManager
constructor
Initializes the task manager.
-
#invoke_task(task) ⇒ Object
Invokes a task.
-
#invoke_task_chain_containing(task_name) ⇒ Object
Invokes the task chain, that contains the requested task.
-
#invoke_task_oneshot(task_name) ⇒ Object
Invokes a task without dependencies.
-
#task_by_name(name) ⇒ Task
Finds a task by its name.
Constructor Details
#initialize ⇒ TaskManager
Initializes the task manager
27 28 29 30 31 |
# File 'lib/avodeploy/task/task_manager.rb', line 27 def initialize @chains = [] @remote_env = nil @local_env = nil end |
Instance Attribute Details
#chains ⇒ Object (readonly)
Returns the value of attribute chains.
24 25 26 |
# File 'lib/avodeploy/task/task_manager.rb', line 24 def chains @chains end |
#dependencies ⇒ Object (readonly)
Returns the value of attribute dependencies.
23 24 25 |
# File 'lib/avodeploy/task/task_manager.rb', line 23 def dependencies @dependencies end |
Instance Method Details
#add_task(name, options, &block) ⇒ Object
Adds a task to the task manager
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/avodeploy/task/task_manager.rb', line 38 def add_task(name, , &block) position = :after standalone = true if .has_key?(:before) position = :before end key = name if .has_key?(:before) key = [:before] standalone = false elsif .has_key?(:after) key = [:after] standalone = false end if standalone == false idx = find_chain_index_containing(key) @chains[idx].delete(name) @chains[idx].insert_at(position, key, [ name, Task.from_task_block(name, , &block) ]) else chain = {} chain[name] = Task.from_task_block(name, , &block) @chains << chain end end |
#execute_for_each_target(task, env) ⇒ Object
Executes a task for all defined targets
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/avodeploy/task/task_manager.rb', line 130 def execute_for_each_target(task, env) raise ArgumentError, 'task must be a task' unless task.kind_of?(Task) raise ArgumentError, 'env must be a RemoteTaskExecutionEnvironment' unless env.kind_of?(RemoteTaskExecutionEnvironment) avo = AvoDeploy::Deployment.instance avo.config.targets.each_pair do |key, target| avo.log.info "invoking task #{task.name} for target #{target.name}..." env.config.merge!(target.config) env.establish_connection task.invoke(env) end end |
#find_chain_index_containing(name) ⇒ Object
Finds the chain containing a specifc task
84 85 86 87 88 89 90 91 92 |
# File 'lib/avodeploy/task/task_manager.rb', line 84 def find_chain_index_containing(name) @chains.each_with_index do |chain, idx| if chain.has_key?(name) return idx end end raise RuntimeError, "could not find a chain containing task #{name}" end |
#invoke_task(task) ⇒ Object
Invokes a task
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/avodeploy/task/task_manager.rb', line 150 def invoke_task(task) raise ArgumentError, 'task must be a task' unless task.kind_of?(Task) avo = AvoDeploy::Deployment.instance env = nil if task.scope == :remote if @remote_env.nil? @remote_env = RemoteTaskExecutionEnvironment.new(avo.config.config) end env = @remote_env elsif task.scope == :local if @local_env.nil? @local_env = LocalTaskExecutionEnvironment.new(avo.config.config) end env = @local_env else raise RuntimeError, 'scope must either be remote or local' end scm_provider = AvoDeploy::ScmProvider::ScmProvider.new(env, avo.config.get(:scm)) env.scm_provider = scm_provider # if remote task -> execute for each target if task.scope == :remote execute_for_each_target(task, env) else task.invoke(env) end end |
#invoke_task_chain_containing(task_name) ⇒ Object
Invokes the task chain, that contains the requested task
112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/avodeploy/task/task_manager.rb', line 112 def invoke_task_chain_containing(task_name) task_name = task_name.to_sym if task_name.is_a?(String) cidx = find_chain_index_containing(task_name) begin @chains[cidx].each_pair do |name, task| invoke_task(task) end rescue Exception => e AvoDeploy::Deployment.instance.handle_abort(e) end end |
#invoke_task_oneshot(task_name) ⇒ Object
Invokes a task without dependencies
97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/avodeploy/task/task_manager.rb', line 97 def invoke_task_oneshot(task_name) task_name = task_name.to_sym if task_name.is_a?(String) cidx = find_chain_index_containing(task_name) begin invoke_task(@chains[cidx][task_name]) rescue Exception => e AvoDeploy::Deployment.instance.handle_abort(e) end end |
#task_by_name(name) ⇒ Task
Finds a task by its name
73 74 75 76 77 78 |
# File 'lib/avodeploy/task/task_manager.rb', line 73 def task_by_name(name) name = name.to_sym if name.is_a?(String) cidx = find_chain_index_containing(name) @chains[cidx][name] end |