Sha256: 88c90976070a588fba33c43a5a1f94fb7d4a2a5be2dbc65c38ea02fe7acd99c3
Contents?: true
Size: 1.64 KB
Versions: 1
Compression:
Stored size: 1.64 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 log.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) log.debug(sorted_graph_log) layers.each_with_index do |layer, index| log.debug("Saving manager #{ems.name} | Layer #{index}") layer.each do |inventory_collection| save_inventory_object_inventory(ems, inventory_collection) unless inventory_collection.saved? end log.debug("Saved manager #{ems.name} | Layer #{index}") end log.debug("Saving manager #{ems.name}...Complete") end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
inventory_refresh-0.1.0 | lib/inventory_refresh/save_collection/topological_sort.rb |