8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/foreman_inventory_upload/async/create_missing_insights_facets.rb', line 8
def run
organization = ::Organization.find(input[:organization_id])
hosts_without_facets = ::ForemanInventoryUpload::Generators::Queries.for_org(organization, hosts_query: 'null? insights_uuid')
facet_count = hosts_without_facets.count
hosts_without_facets.each do |batch|
facets = batch.pluck(:id, 'katello_subscription_facets.uuid').map do |host_id, uuid|
{
host_id: host_id,
uuid: uuid,
}
end
InsightsFacet.upsert_all(facets, unique_by: :host_id) unless facets.empty?
end
output[:result] = facet_count.zero? ? _("There were no missing Insights facets") : format(_("Missing Insights facets created: %s"), facet_count)
Rails.logger.info output[:result]
end
|