Class: InsightsCloud::Async::InsightsResolutionsSync

Inherits:
Actions::EntryAction
  • Object
show all
Includes:
ForemanRhCloud::Async::ExponentialBackoff, ForemanRhCloud::CertAuth
Defined in:
lib/insights_cloud/async/insights_resolutions_sync.rb

Constant Summary collapse

RULE_ID_REGEX =
/[^:]*:(?<id>.*)/

Instance Method Summary collapse

Methods included from ForemanRhCloud::Async::ExponentialBackoff

#attempts_before_next_interval, #done!, #done?, #invoke_external_task, #poll_external_task, #poll_intervals

Methods included from ForemanRhCloud::CertAuth

#cert_auth_available?, #execute_cloud_request, #foreman_certificate

Methods included from CandlepinCache

#candlepin_id_cert, #cp_owner_id, #upstream_owner

Methods included from ForemanRhCloud::CloudRequest

#execute_cloud_request

Instance Method Details

#loggerObject



29
30
31
# File 'lib/insights_cloud/async/insights_resolutions_sync.rb', line 29

def logger
  action_logger
end

#try_executeObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/insights_cloud/async/insights_resolutions_sync.rb', line 11

def try_execute
  InsightsResolution.transaction do
    InsightsResolution.delete_all
    rule_ids = relevant_rules
    Organization.all.each do |organization|
      checker = ::Katello::UpstreamConnectionChecker.new(organization)
      if !cert_auth_available?(organization) || organization.manifest_expired? || !checker.can_connect?
        logger.info("A manifest is not available for org: #{organization.name}, or it has expired, or been deleted. skipping resolutions sync")
        next
      end
      api_response = query_insights_resolutions(rule_ids, organization) unless rule_ids.empty?
      written_rules = write_resolutions(api_response) if api_response
      rule_ids -= Array(written_rules)
    end
  end
  done!
end