class InventorySync::Async::InventoryFullSync
Public Instance Methods
plan(organization)
click to toggle source
Calls superclass method
# File lib/inventory_sync/async/inventory_full_sync.rb, line 7 def plan(organization) unless cert_auth_available?(organization) logger.debug('Cloud authentication is not available, skipping inventory hosts sync') return end super(organization) end
rescue_strategy_for_self()
click to toggle source
# File lib/inventory_sync/async/inventory_full_sync.rb, line 50 def rescue_strategy_for_self Dynflow::Action::Rescue::Fail 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(affected_host_ids) @omitted_ids = Set.new(user_omitted_host_ids) # Remove user-omitted hosts from subscribed set. In normal operation, affected_host_ids # already excludes user-omitted hosts via for_slice, but this handles edge cases like # a host transitioning from uploaded to user-omitted between syncs. @subscribed_hosts_ids.subtract(@omitted_ids) InventorySync::InventoryStatus.transaction do InventorySync::InventoryStatus.where(host_id: @subscribed_hosts_ids).delete_all InventorySync::InventoryStatus.where(host_id: @omitted_ids).delete_all yield add_missing_hosts_statuses(@subscribed_hosts_ids) # any remaining hosts after yield are disconnected add_user_omitted_host_statuses(@omitted_ids) host_statuses[:disconnect] += @subscribed_hosts_ids.size host_statuses[:user_omitted] += @omitted_ids.size end logger.debug("Synced hosts count: #{host_statuses[:sync]}") logger.debug("Disconnected hosts count: #{host_statuses[:disconnect]}") logger.debug("User-omitted hosts count: #{host_statuses[:user_omitted]}") output[:host_statuses] = host_statuses end
update_statuses_batch() { || ... }
click to toggle source
# File lib/inventory_sync/async/inventory_full_sync.rb, line 41 def update_statuses_batch results = yield existing_hosts = results.status_hashes.select { |hash| @subscribed_hosts_ids.include?(hash[:host_id]) } update_hosts_status(existing_hosts) host_statuses[:sync] += existing_hosts.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 63 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
add_user_omitted_host_statuses(host_ids)
click to toggle source
# File lib/inventory_sync/async/inventory_full_sync.rb, line 75 def add_user_omitted_host_statuses(host_ids) InventorySync::InventoryStatus.create( host_ids.map do |host_id| { host_id: host_id, status: InventorySync::InventoryStatus::USER_OMITTED, reported_at: DateTime.current, } end ) end
affected_host_ids()
click to toggle source
# File lib/inventory_sync/async/inventory_full_sync.rb, line 95 def affected_host_ids ForemanInventoryUpload::Generators::Queries.for_slice( Host.unscoped.where(organization: organizations) ).pluck(:id) end
host_statuses()
click to toggle source
# File lib/inventory_sync/async/inventory_full_sync.rb, line 87 def host_statuses @host_statuses ||= { sync: 0, disconnect: 0, user_omitted: 0, } end
update_hosts_status(status_hashes)
click to toggle source
# File lib/inventory_sync/async/inventory_full_sync.rb, line 56 def update_hosts_status(status_hashes) # create Inventory statuses InventorySync::InventoryStatus.create(status_hashes) updated_ids = status_hashes.map { |hash| hash[:host_id] } @subscribed_hosts_ids.subtract(updated_ids) end
user_omitted_host_ids()
click to toggle source
# File lib/inventory_sync/async/inventory_full_sync.rb, line 101 def user_omitted_host_ids param_name = InsightsCloud.enable_client_param_inventory # Use search_for to respect parameter inheritance (global, org, hostgroup, host) # This matches the same logic used by for_slice, ensuring consistency Host.unscoped .where(organization: organizations) .joins(:subscription_facet) .search_for("params.#{param_name} = f") .pluck(:id) end