class InventorySync::Async::QueryInventoryJob

Public Instance Methods

plan(organizations, **params) click to toggle source
# 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_execute() click to toggle source
# 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

Private Instance Methods

action_name() click to toggle source
# File lib/inventory_sync/async/query_inventory_job.rb, line 85
def action_name
  'inventory query'
end
logger() click to toggle source
# File lib/inventory_sync/async/query_inventory_job.rb, line 69
def logger
  action_logger
end
organizations() click to toggle source
# File lib/inventory_sync/async/query_inventory_job.rb, line 81
def organizations
  @organizations ||= Organization.where(id: input[:organization_ids])
end
query_inventory(organization, page = 1) click to toggle source
# File lib/inventory_sync/async/query_inventory_job.rb, line 53
def query_inventory(organization, page = 1)
  hosts_inventory_response = execute_cloud_request(
    organization: organization,
    method: :get,
    url: request_url,
    headers: {
      params: {
        per_page: 100,
        page: page,
      },
    }
  )

  JSON.parse(hosts_inventory_response)
end
request_url() click to toggle source
# File lib/inventory_sync/async/query_inventory_job.rb, line 73
def request_url
  ForemanInventoryUpload.inventory_export_url
end
rescue_strategy_for_self() click to toggle source
# File lib/inventory_sync/async/query_inventory_job.rb, line 77
def rescue_strategy_for_self
  Dynflow::Action::Rescue::Fail
end