class InventorySync::Async::InventoryHostsSync
Constants
- MAX_IP_STRING_SIZE
Public Instance Methods
create_facets() { || ... }
click to toggle source
# File lib/inventory_sync/async/inventory_hosts_sync.rb, line 22 def create_facets # get the results from the event results = yield add_missing_insights_facets(results.organization, results.host_uuids) results end
create_missing_hosts() { || ... }
click to toggle source
# File lib/inventory_sync/async/inventory_hosts_sync.rb, line 29 def create_missing_hosts results = yield missing_hosts = results.missing_hosts.map { |host| to_missing_host_record(host, results.organization) } # remove records that are no longer in the query results InsightsMissingHost. where.not(insights_id: missing_hosts.map { |host_hash| host_hash[:insights_id] }). where(organization_id: results.organization.id).delete_all # readd new hosts that appear in the results, but the subscription_id is missing from the DB. InsightsMissingHost.upsert_all(missing_hosts) if missing_hosts.present? end
plan(organizations)
click to toggle source
Calls superclass method
# File lib/inventory_sync/async/inventory_hosts_sync.rb, line 10 def plan(organizations) # by default the tasks will be executed concurrently super(organizations) plan_self_host_sync end
rescue_strategy_for_self()
click to toggle source
# File lib/inventory_sync/async/inventory_hosts_sync.rb, line 40 def rescue_strategy_for_self Dynflow::Action::Rescue::Fail end
setup_facet_transaction() { || ... }
click to toggle source
# File lib/inventory_sync/async/inventory_hosts_sync.rb, line 16 def setup_facet_transaction ActiveRecord::Base.transaction do yield end end
Private Instance Methods
action_name()
click to toggle source
# File lib/inventory_sync/async/inventory_hosts_sync.rb, line 78 def action_name 'inventory hosts sync' end
add_missing_insights_facets(organization, uuids_hash)
click to toggle source
# File lib/inventory_sync/async/inventory_hosts_sync.rb, line 46 def add_missing_insights_facets(organization, uuids_hash) # Filter out hosts that belong to different organization (although they are visible by the query) unrelated_hosts = Host.where.not(organization_id: organization.id).where(id: uuids_hash.keys).pluck(:id) all_facets = uuids_hash.except(unrelated_hosts).map do |host_id, uuid| { host_id: host_id, uuid: uuid, } end InsightsFacet.upsert_all(all_facets, unique_by: :host_id) unless all_facets.empty? end
plan_self_host_sync()
click to toggle source
# File lib/inventory_sync/async/inventory_hosts_sync.rb, line 74 def plan_self_host_sync plan_action InventorySync::Async::InventorySelfHostSync end
to_ip_address_string(ip_addresses)
click to toggle source
# File lib/inventory_sync/async/inventory_hosts_sync.rb, line 69 def to_ip_address_string(ip_addresses) string_size = 0 ip_addresses.take_while { |address| (string_size += address.length) <= MAX_IP_STRING_SIZE } end
to_missing_host_record(host_result, organization)
click to toggle source
# File lib/inventory_sync/async/inventory_hosts_sync.rb, line 59 def to_missing_host_record(host_result, organization) { name: host_result['fqdn'], insights_id: host_result['id'], rhsm_id: host_result['subscription_manager_id'], ip_address: to_ip_address_string(host_result['ip_addresses']), organization_id: organization.id, } end