Class: Actions::RemoteExecution::RunHostJob
- Inherits:
-
EntryAction
- Object
- EntryAction
- Actions::RemoteExecution::RunHostJob
- Includes:
- Helpers::WithContinuousOutput, Helpers::WithDelegatedAction
- Defined in:
- app/lib/actions/remote_execution/run_host_job.rb
Instance Method Summary collapse
- #check_exit_status ⇒ Object
- #continuous_output_providers ⇒ Object
-
#exit_status ⇒ Object
rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity.
-
#fill_continuous_output(continuous_output) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity.
- #finalize(*args) ⇒ Object
- #humanized_input ⇒ Object
- #humanized_name ⇒ Object
- #humanized_output ⇒ Object
- #live_output ⇒ Object
- #plan(job_invocation, host, template_invocation, proxy_selector = ::RemoteExecutionProxySelector.new, options = {}) ⇒ Object
- #queue ⇒ Object
- #rescue_strategy ⇒ Object
- #resource_locks ⇒ Object
Instance Method Details
#check_exit_status ⇒ Object
62 63 64 65 |
# File 'app/lib/actions/remote_execution/run_host_job.rb', line 62 def check_exit_status error! ForemanTasks::Task::TaskCancelledException.new(_('Task cancelled')) if delegated_action && delegated_action.output[:cancel_sent] error! _('Job execution failed') if exit_status.to_s != '0' end |
#continuous_output_providers ⇒ Object
89 90 91 |
# File 'app/lib/actions/remote_execution/run_host_job.rb', line 89 def continuous_output_providers super << self end |
#exit_status ⇒ Object
rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
116 117 118 |
# File 'app/lib/actions/remote_execution/run_host_job.rb', line 116 def exit_status delegated_output[:exit_status] end |
#fill_continuous_output(continuous_output) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'app/lib/actions/remote_execution/run_host_job.rb', line 94 def fill_continuous_output(continuous_output) delegated_output.fetch('result', []).each do |raw_output| continuous_output.add_raw_output(raw_output) end = (continuous_output. || task.ended_at).to_f + 1 if task.state == 'stopped' && task.result == 'cancelled' continuous_output.add_output(_('Job cancelled by user'), 'debug', ) else fill_planning_errors_to_continuous_output(continuous_output) unless exit_status end if exit_status continuous_output.add_output(_('Exit status: %s') % exit_status, 'stdout', ) elsif run_step && run_step.error continuous_output.add_output(_('Job finished with error') + ": #{run_step.error.exception_class} - #{run_step.error.}", 'debug', ) end rescue => e continuous_output.add_exception(_('Error loading data from proxy'), e) end |
#finalize(*args) ⇒ Object
57 58 59 60 |
# File 'app/lib/actions/remote_execution/run_host_job.rb', line 57 def finalize(*args) update_host_status check_exit_status end |
#humanized_input ⇒ Object
72 73 74 75 |
# File 'app/lib/actions/remote_execution/run_host_job.rb', line 72 def humanized_input N_('%{description} on %{host}') % { :host => input[:host].try(:[], :name), :description => input[:description].try(:capitalize) || input[:job_category] } end |
#humanized_name ⇒ Object
77 78 79 |
# File 'app/lib/actions/remote_execution/run_host_job.rb', line 77 def humanized_name N_('Remote action:') end |
#humanized_output ⇒ Object
85 86 87 |
# File 'app/lib/actions/remote_execution/run_host_job.rb', line 85 def humanized_output continuous_output.humanize end |
#live_output ⇒ Object
67 68 69 70 |
# File 'app/lib/actions/remote_execution/run_host_job.rb', line 67 def live_output continuous_output.sort! continuous_output.raw_outputs end |
#plan(job_invocation, host, template_invocation, proxy_selector = ::RemoteExecutionProxySelector.new, options = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/lib/actions/remote_execution/run_host_job.rb', line 18 def plan(job_invocation, host, template_invocation, proxy_selector = ::RemoteExecutionProxySelector.new, = {}) action_subject(host, :job_category => job_invocation.job_category, :description => job_invocation.description) template_invocation.host_id = host.id template_invocation.run_host_job_task_id = task.id template_invocation.save! link!(job_invocation) link!(template_invocation) (host, template_invocation) raise _('Could not use any template used in the job invocation') if template_invocation.blank? provider_type = template_invocation.template.provider_type.to_s proxy = determine_proxy!(proxy_selector, provider_type, host) renderer = InputTemplateRenderer.new(template_invocation.template, host, template_invocation) script = renderer.render raise _('Failed rendering template: %s') % renderer. unless script provider = template_invocation.template.provider secrets = { :ssh_password => job_invocation.password || provider.ssh_password(host), :key_passphrase => job_invocation.key_passphrase || provider.ssh_key_passphrase(host), :sudo_password => job_invocation.sudo_password || provider.sudo_password(host) } = { :hostname => provider.find_ip_or_hostname(host), :script => script, :execution_timeout_interval => job_invocation.execution_timeout_interval, :secrets => secrets, :use_batch_triggering => true} = provider.(template_invocation, host) .merge() plan_delegated_action(proxy, ForemanRemoteExecutionCore::Actions::RunScript, ) plan_self end |
#queue ⇒ Object
10 11 12 |
# File 'app/lib/actions/remote_execution/run_host_job.rb', line 10 def queue ForemanRemoteExecution::DYNFLOW_QUEUE end |
#rescue_strategy ⇒ Object
81 82 83 |
# File 'app/lib/actions/remote_execution/run_host_job.rb', line 81 def rescue_strategy ::Dynflow::Action::Rescue::Fail end |
#resource_locks ⇒ Object
14 15 16 |
# File 'app/lib/actions/remote_execution/run_host_job.rb', line 14 def resource_locks :link end |