Class: Actions::RemoteExecution::RunHostsJob

Inherits:
ActionWithSubPlans
  • Object
show all
Includes:
Actions::RecurringAction, Dynflow::Action::WithBulkSubPlans, Dynflow::Action::WithPollingSubPlans
Defined in:
app/lib/actions/remote_execution/run_hosts_job.rb

Defined Under Namespace

Classes: CheckOnProxyActions

Instance Method Summary collapse

Instance Method Details

#batch(from, size) ⇒ Object



64
65
66
# File 'app/lib/actions/remote_execution/run_hosts_job.rb', line 64

def batch(from, size)
  hosts.offset(from).limit(size)
end

#create_sub_plansObject



37
38
39
40
41
42
43
44
45
46
47
# File 'app/lib/actions/remote_execution/run_hosts_job.rb', line 37

def create_sub_plans
  proxy_selector = RemoteExecutionProxySelector.new

  current_batch.map do |host|
    # composer creates just "pattern" for template_invocations because target is evaluated
    # during actual run (here) so we build template invocations from these patterns
    template_invocation = job_invocation.pattern_template_invocation_for_host(host).deep_clone
    template_invocation.host_id = host.id
    trigger(RunHostJob, job_invocation, host, template_invocation, proxy_selector, { :use_concurrency_control => uses_concurrency_control })
  end
end

#delay(delay_options, job_invocation) ⇒ Object



20
21
22
23
24
25
# File 'app/lib/actions/remote_execution/run_hosts_job.rb', line 20

def delay(delay_options, job_invocation)
  task.add_missing_task_groups(job_invocation.task_group)
  job_invocation.targeting.resolve_hosts! if job_invocation.targeting.static? && !job_invocation.targeting.resolved?
  input.update :job_invocation => job_invocation.to_action_input
  super delay_options, job_invocation
end

#finalizeObject



49
50
51
52
53
54
55
56
57
# File 'app/lib/actions/remote_execution/run_hosts_job.rb', line 49

def finalize
  job_invocation.password = job_invocation.key_passphrase = job_invocation.effective_user_password = nil
  job_invocation.save!

  Rails.logger.debug "cleaning cache for keys that begin with 'job_invocation_#{job_invocation.id}'"
  Rails.cache.delete_matched(/\A#{JobInvocation::CACHE_PREFIX}_#{job_invocation.id}/)
  # creating the success notification should be the very last thing this tasks do
  job_invocation.build_notification.deliver!
end

#hostsObject



80
81
82
# File 'app/lib/actions/remote_execution/run_hosts_job.rb', line 80

def hosts
  job_invocation.targeting.hosts.order("#{TargetingHost.table_name}.id")
end

#humanized_inputObject



100
101
102
# File 'app/lib/actions/remote_execution/run_hosts_job.rb', line 100

def humanized_input
  input.fetch(:job_invocation, {}).fetch(:description, '')
end

#humanized_nameObject



104
105
106
# File 'app/lib/actions/remote_execution/run_hosts_job.rb', line 104

def humanized_name
  '%s:' % _(super)
end

#initiateObject



68
69
70
71
# File 'app/lib/actions/remote_execution/run_hosts_job.rb', line 68

def initiate
  output[:host_count] = total_count
  super
end

#job_invocationObject



59
60
61
62
# File 'app/lib/actions/remote_execution/run_hosts_job.rb', line 59

def job_invocation
  id = input[:job_invocation_id] || input.fetch(:job_invocation, {})[:id]
  @job_invocation ||= JobInvocation.find(id)
end

#plan(job_invocation) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'app/lib/actions/remote_execution/run_hosts_job.rb', line 27

def plan(job_invocation)
  job_invocation.task_group.save! if job_invocation.task_group.try(:new_record?)
  task.add_missing_task_groups(job_invocation.task_group) if job_invocation.task_group
  action_subject(job_invocation)
  job_invocation.targeting.resolve_hosts! if job_invocation.targeting.dynamic? || !job_invocation.targeting.resolved?
  set_up_concurrency_control job_invocation
  input.update(:job_category => job_invocation.job_category)
  plan_self(:job_invocation_id => job_invocation.id)
end

#queueObject



16
17
18
# File 'app/lib/actions/remote_execution/run_hosts_job.rb', line 16

def queue
  ForemanRemoteExecution::DYNFLOW_QUEUE
end

#rescue_strategyObject



92
93
94
# File 'app/lib/actions/remote_execution/run_hosts_job.rb', line 92

def rescue_strategy
  ::Dynflow::Action::Rescue::Skip
end

#run(event = nil) ⇒ Object



96
97
98
# File 'app/lib/actions/remote_execution/run_hosts_job.rb', line 96

def run(event = nil)
  super unless event == Dynflow::Action::Skip
end

#set_up_concurrency_control(invocation) ⇒ Object



84
85
86
87
88
89
90
# File 'app/lib/actions/remote_execution/run_hosts_job.rb', line 84

def set_up_concurrency_control(invocation)
  limit_concurrency_level invocation.concurrency_level unless invocation.concurrency_level.nil?
  unless invocation.time_span.nil?
    distribute_over_time(invocation.time_span,
      invocation.targeting.hosts.count)
  end
end

#total_countObject



73
74
75
76
77
78
# File 'app/lib/actions/remote_execution/run_hosts_job.rb', line 73

def total_count
  # For compatibility with already existing tasks
  return output[:total_count] unless output.has_key?(:host_count) || task.pending?

  output[:host_count] || hosts.count
end