Sha256: 710ab87337c199d4c59c1e039217763f3de12842b178aced572906d4cd800e98

Contents?: true

Size: 1.66 KB

Versions: 13

Compression:

Stored size: 1.66 KB

Contents

require "inventory_refresh/logging"
require "inventory_refresh/inventory_collection/graph"
require "inventory_refresh/save_collection/base"

module InventoryRefresh::SaveCollection
  class TopologicalSort < InventoryRefresh::SaveCollection::Base
    class << self
      # Saves the passed InventoryCollection objects by doing a topology sort of the graph, then going layer by layer
      # and saving InventoryCollection object in each layer.
      #
      # @param ems [ExtManagementSystem] manager owning the inventory_collections
      # @param inventory_collections [Array<InventoryRefresh::InventoryCollection>] array of InventoryCollection objects
      #        for saving
      def save_collections(ems, inventory_collections)
        graph = InventoryRefresh::InventoryCollection::Graph.new(inventory_collections)
        graph.build_directed_acyclic_graph!

        layers = InventoryRefresh::Graph::TopologicalSort.new(graph).topological_sort

        logger.debug("Saving manager #{ems.name}...")

        sorted_graph_log = "Topological sorting of manager #{ems.name} resulted in these layers processable in parallel:\n"
        sorted_graph_log += graph.to_graphviz(:layers => layers)
        logger.debug(sorted_graph_log)

        layers.each_with_index do |layer, index|
          logger.debug("Saving manager #{ems.name} | Layer #{index}")
          layer.each do |inventory_collection|
            save_inventory_object_inventory(ems, inventory_collection) unless inventory_collection.saved?
          end
          logger.debug("Saved manager #{ems.name} | Layer #{index}")
        end

        logger.debug("Saving manager #{ems.name}...Complete")
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
inventory_refresh-2.2.0 lib/inventory_refresh/save_collection/topological_sort.rb
inventory_refresh-2.1.1 lib/inventory_refresh/save_collection/topological_sort.rb
inventory_refresh-2.1.0 lib/inventory_refresh/save_collection/topological_sort.rb
inventory_refresh-2.0.0 lib/inventory_refresh/save_collection/topological_sort.rb
inventory_refresh-1.1.0 lib/inventory_refresh/save_collection/topological_sort.rb
inventory_refresh-1.0.0 lib/inventory_refresh/save_collection/topological_sort.rb
inventory_refresh-0.2.3 lib/inventory_refresh/save_collection/topological_sort.rb
inventory_refresh-0.2.2 lib/inventory_refresh/save_collection/topological_sort.rb
inventory_refresh-0.2.1 lib/inventory_refresh/save_collection/topological_sort.rb
inventory_refresh-0.2.0 lib/inventory_refresh/save_collection/topological_sort.rb
inventory_refresh-0.1.3 lib/inventory_refresh/save_collection/topological_sort.rb
inventory_refresh-0.1.2 lib/inventory_refresh/save_collection/topological_sort.rb
inventory_refresh-0.1.1 lib/inventory_refresh/save_collection/topological_sort.rb