Class: InventorySync::Async::QueryInventoryJob

Inherits:
Actions::EntryAction
  • Object
show all
Includes:
ActiveSupport::Callbacks, ForemanRhCloud::Async::ExponentialBackoff, ForemanRhCloud::CertAuth
Defined in:
lib/inventory_sync/async/query_inventory_job.rb

Direct Known Subclasses

InventoryHostsSync, InventorySelfHostSync

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 InsightsCloud::CandlepinCache

#candlepin_id_cert, #cp_owner_id, #upstream_owner

Methods included from ForemanRhCloud::CloudRequest

#execute_cloud_request

Instance Method Details

#plan(organizations, **params) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/inventory_sync/async/query_inventory_job.rb', line 12

def plan(organizations, **params)
  actual_params = params.merge(
    {
      organization_ids: Array(organizations).map(&:id),
    }
  )

  plan_self(actual_params)
end

#try_executeObject



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
# File 'lib/inventory_sync/async/query_inventory_job.rb', line 22

def try_execute
  run_callbacks :iteration do
    organizations.each do |organization|
      if !cert_auth_available?(organization) || organization.manifest_expired?
        logger.debug("Subscription manifest not available, skipping #{action_name} for organization #{organization.name}")
        next
      end

      logger.debug("Executing #{action_name} for organization #{organization.name}")

      page = 1
      loop do
        api_response = query_inventory(organization, page)
        results = HostResult.new(api_response, organization)
        logger.debug("Downloaded cloud inventory data: #{results.percentage}%")

        run_callbacks :step do
          results
        end

        page += 1
        break if results.last?
      end
    end
  end
  # declare the action as finished to stop iterations
  done!
end