Class: InsightsCloud::Async::InsightsRulesSync

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

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

Methods included from CandlepinCache

#candlepin_id_cert, #cp_owner_id, #upstream_owner

Methods included from ForemanRhCloud::CloudRequest

#execute_cloud_request

Instance Method Details

#loggerObject



43
44
45
# File 'lib/insights_cloud/async/insights_rules_sync.rb', line 43

def logger
  action_logger
end

#plan(organizations) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/insights_cloud/async/insights_rules_sync.rb', line 9

def plan(organizations)
  # since the tasks are not connected, we need to force sequence execution here
  # to make sure we don't run resolutions until we synced all our rules
  sequence do
    plan_self(organization_ids: organizations.map(&:id))
    plan_resolutions
  end
end

#plan_resolutionsObject



18
19
20
# File 'lib/insights_cloud/async/insights_rules_sync.rb', line 18

def plan_resolutions
  plan_action InsightsResolutionsSync
end

#try_executeObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/insights_cloud/async/insights_rules_sync.rb', line 22

def try_execute
  offset = 0
  InsightsRule.transaction do
    organizations.each do |organization|
      loop do
        api_response = query_insights_rules(offset, organization)
        results = RulesResult.new(api_response)
        logger.debug("Downloaded #{offset + results.count} of #{results.total}")
        write_rules_page(results.rules)
        offset += results.count
        output[:rules_count] = results.total
        break if offset >= results.total
      end
    end

    # Remove all rules that do not have hits associated with them
    cleanup_rules
  end
  done!
end