Class: InsightsCloud::Async::ConnectorPlaybookExecutionReporterTask

Inherits:
Actions::EntryAction
  • Object
show all
Includes:
Dynflow::Action::Polling, ForemanRhCloud::CertAuth
Defined in:
lib/insights_cloud/async/connector_playbook_execution_reporter_task.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ForemanRhCloud::CertAuth

#cert_auth_available?, #execute_cloud_request

Methods included from CandlepinCache

#candlepin_id_cert, #cp_owner_id, #upstream_owner

Methods included from ForemanRhCloud::CloudRequest

#execute_cloud_request

Class Method Details

.connector_feature_idObject



11
12
13
# File 'lib/insights_cloud/async/connector_playbook_execution_reporter_task.rb', line 11

def self.connector_feature_id
  @connector_feature_id ||= RemoteExecutionFeature.feature!(:rh_cloud_connector_run_playbook).id
end

.subscribeObject



7
8
9
# File 'lib/insights_cloud/async/connector_playbook_execution_reporter_task.rb', line 7

def self.subscribe
  Actions::RemoteExecution::RunHostsJob
end

Instance Method Details

#all_hosts_finished?(current_status) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
56
57
# File 'lib/insights_cloud/async/connector_playbook_execution_reporter_task.rb', line 53

def all_hosts_finished?(current_status)
  current_status[:hosts_state].values.all? do |status|
    ActiveModel::Type::Boolean.new.cast(status['report_done'] == true)
  end
end

#done?(current_status = invocation_status) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/insights_cloud/async/connector_playbook_execution_reporter_task.rb', line 45

def done?(current_status = invocation_status)
  ActiveModel::Type::Boolean.new.cast(current_status[:task_state][:task_done_reported])
end

#invoke_external_taskObject

noop, we don’t want to do anything when the polling task starts



60
61
62
# File 'lib/insights_cloud/async/connector_playbook_execution_reporter_task.rb', line 60

def invoke_external_task
  poll_external_task
end

#job_finished?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/insights_cloud/async/connector_playbook_execution_reporter_task.rb', line 49

def job_finished?
  job_invocation.finished?
end

#plan(job_invocation) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/insights_cloud/async/connector_playbook_execution_reporter_task.rb', line 15

def plan(job_invocation)
  return unless connector_playbook_job?(job_invocation)

  @job_invocation = job_invocation

  invocation_inputs = invocation_inputs(job_invocation)
  report_url = invocation_inputs['report_url']
  report_interval = [invocation_inputs['report_interval'].to_i, 5].max
  correlation_id = invocation_inputs['correlation_id']

  plan_self(
    current_org_id: job_invocation.targeted_hosts.first.organization_id,
    report_url: report_url,
    report_interval: report_interval,
    job_invocation_id: job_invocation.id,
    correlation_id: correlation_id
  )
end

#poll_external_taskObject



64
65
66
67
68
69
70
71
# File 'lib/insights_cloud/async/connector_playbook_execution_reporter_task.rb', line 64

def poll_external_task
  current_status = invocation_status
  report_job_progress(current_status)
  # record the current state and increment the sequence for the next invocation
  {
    invocation_status: current_status,
  }
end

#poll_intervalsObject



73
74
75
# File 'lib/insights_cloud/async/connector_playbook_execution_reporter_task.rb', line 73

def poll_intervals
  [report_interval]
end

#rescue_strategy_for_selfObject



41
42
43
# File 'lib/insights_cloud/async/connector_playbook_execution_reporter_task.rb', line 41

def rescue_strategy_for_self
  Dynflow::Action::Rescue::Skip
end

#run(event = nil) ⇒ Object



34
35
36
37
38
39
# File 'lib/insights_cloud/async/connector_playbook_execution_reporter_task.rb', line 34

def run(event = nil)
  # Handle skip events
  return if event == Dynflow::Action::Skip

  super
end