Sha256: 1f852e55fed9006c81bb117c4dce2f3b11eb9d507eced4ca408b5167f15f5d23

Contents?: true

Size: 883 Bytes

Versions: 7

Compression:

Stored size: 883 Bytes

Contents

module InventorySync
  module Async
    class InventoryHostsSync < QueryInventoryJob
      set_callback :iteration, :around, :setup_facet_transaction
      set_callback :step, :around, :create_facets

      def setup_facet_transaction
        InsightsFacet.transaction do
          yield
        end
      end

      def create_facets
        # get the results from the event
        results = yield
        add_missing_insights_facets(results.host_uuids)
        results
      end

      private

      def add_missing_insights_facets(uuids_hash)
        existing_facets = InsightsFacet.where(host_id: uuids_hash.keys).pluck(:host_id)
        missing_facets = uuids_hash.except(*existing_facets).map do |host_id, uuid|
          {
            host_id: host_id,
            uuid: uuid,
          }
        end
        InsightsFacet.create(missing_facets)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
foreman_rh_cloud-3.0.22 lib/inventory_sync/async/inventory_hosts_sync.rb
foreman_rh_cloud-4.0.22 lib/inventory_sync/async/inventory_hosts_sync.rb
foreman_rh_cloud-4.0.21.1 lib/inventory_sync/async/inventory_hosts_sync.rb
foreman_rh_cloud-3.0.21.1 lib/inventory_sync/async/inventory_hosts_sync.rb
foreman_rh_cloud-3.0.21 lib/inventory_sync/async/inventory_hosts_sync.rb
foreman_rh_cloud-3.0.20 lib/inventory_sync/async/inventory_hosts_sync.rb
foreman_rh_cloud-3.0.19 lib/inventory_sync/async/inventory_hosts_sync.rb