class InventorySync::Async::InventoryFullSync

Public Instance Methods

plan(organization) click to toggle source
# File lib/inventory_sync/async/inventory_full_sync.rb, line 7
def plan(organization)
  unless cloud_auth_available?
    logger.debug('Cloud authentication is not available, skipping inventory hosts sync')
    return
  end

  plan_self(organization_id: organization.id)
end
setup_statuses() { || ... } click to toggle source
# File lib/inventory_sync/async/inventory_full_sync.rb, line 16
def setup_statuses
  @subscribed_hosts_ids = Set.new(
    ForemanInventoryUpload::Generators::Queries.for_slice(
      Host.unscoped.where(organization: input[:organization_id])
    ).pluck(:id)
  )

  InventorySync::InventoryStatus.transaction do
    InventorySync::InventoryStatus.where(host_id: @subscribed_hosts_ids).delete_all
    yield
    add_missing_hosts_statuses(@subscribed_hosts_ids)
    host_statuses[:disconnect] += @subscribed_hosts_ids.size
  end

  logger.debug("Synced hosts amount: #{host_statuses[:sync]}")
  logger.debug("Disconnected hosts amount: #{host_statuses[:disconnect]}")
  output[:host_statuses] = host_statuses
end
update_statuses_batch() { || ... } click to toggle source
# File lib/inventory_sync/async/inventory_full_sync.rb, line 35
def update_statuses_batch
  results = yield

  update_hosts_status(results.status_hashes, results.touched)
  host_statuses[:sync] += results.touched.size
end

Private Instance Methods

add_missing_hosts_statuses(hosts_ids) click to toggle source
# File lib/inventory_sync/async/inventory_full_sync.rb, line 49
def add_missing_hosts_statuses(hosts_ids)
  InventorySync::InventoryStatus.create(
    hosts_ids.map do |host_id|
      {
        host_id: host_id,
        status: InventorySync::InventoryStatus::DISCONNECT,
        reported_at: DateTime.current,
      }
    end
  )
end
host_statuses() click to toggle source
# File lib/inventory_sync/async/inventory_full_sync.rb, line 61
def host_statuses
  @host_statuses ||= {
    sync: 0,
    disconnect: 0,
  }
end
update_hosts_status(status_hashes, touched) click to toggle source
# File lib/inventory_sync/async/inventory_full_sync.rb, line 44
def update_hosts_status(status_hashes, touched)
  InventorySync::InventoryStatus.create(status_hashes)
  @subscribed_hosts_ids.subtract(touched)
end