Class: ForemanTasks::RemoteTask
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- ForemanTasks::RemoteTask
- Defined in:
- app/models/foreman_tasks/remote_task.rb
Instance Attribute Summary collapse
-
#result ⇒ Object
Returns the value of attribute result.
Class Method Summary collapse
Instance Method Summary collapse
- #proxy ⇒ Object
- #proxy_input ⇒ Object
-
#trigger(proxy_action_name, input) ⇒ Object
Triggers a task on the proxy “the old way”.
- #update_from_batch_trigger(data, parent = {}) ⇒ Object
Instance Attribute Details
#result ⇒ Object
Returns the value of attribute result.
3 4 5 |
# File 'app/models/foreman_tasks/remote_task.rb', line 3 def result @result end |
Class Method Details
.batch_trigger(operation, remote_tasks) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/models/foreman_tasks/remote_task.rb', line 29 def self.batch_trigger(operation, remote_tasks) remote_tasks.group_by(&:proxy_url).each_value do |group| input_hash = group.reduce({}) do |acc, remote_task| acc.merge(remote_task.execution_plan_id => { :action_input => remote_task.proxy_input, :action_class => remote_task.proxy_action_name }) end results = group.first.proxy.launch_tasks(operation, input_hash) group.each do |remote_task| remote_task.update_from_batch_trigger results.fetch(remote_task.execution_plan_id, {}), results.fetch('parent', {}) end end remote_tasks end |
Instance Method Details
#proxy ⇒ Object
69 70 71 |
# File 'app/models/foreman_tasks/remote_task.rb', line 69 def proxy @proxy ||= ::ProxyAPI::ForemanDynflow::DynflowProxy.new(:url => proxy_url) end |
#proxy_input ⇒ Object
65 66 67 |
# File 'app/models/foreman_tasks/remote_task.rb', line 65 def proxy_input action.proxy_input(task.id) end |
#trigger(proxy_action_name, input) ⇒ Object
Triggers a task on the proxy “the old way”
17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/models/foreman_tasks/remote_task.rb', line 17 def trigger(proxy_action_name, input) response = begin proxy.launch_tasks('single', :action_class => proxy_action_name, :action_input => input) rescue RestClient::Exception => e logger.warn "Could not trigger task on the smart proxy" logger.warn e {} end update_from_batch_trigger(response) save! end |
#update_from_batch_trigger(data, parent = {}) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/models/foreman_tasks/remote_task.rb', line 44 def update_from_batch_trigger(data, parent = {}) # The ID might get overwritten later, but it is a sane default in case of async # triggering where we only get an id of a remote parent self.remote_task_id = execution_plan_id if data['result'] == 'success' self.remote_task_id = data['task_id'] self.state = 'triggered' elsif !parent.empty? self.parent_task_id = parent['task_id'] self.state = 'parent-triggered' else exception = data['exception'] # Tell the action the task on the smart proxy stopped ForemanTasks.dynflow.world.event execution_plan_id, step_id, ::Actions::ProxyAction::ProxyActionStoppedEvent[exception], optional: true end save! end |