class InventoryRefresh::SaveCollection::TopologicalSort
Public Class Methods
save_collections(ems, inventory_collections)
click to toggle source
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
# File lib/inventory_refresh/save_collection/topological_sort.rb, line 14 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.id}...") sorted_graph_log = "Topological sorting of manager #{ems.id} 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.id} | Layer #{index}") layer.each do |inventory_collection| save_inventory_object_inventory(ems, inventory_collection) unless inventory_collection.saved? end logger.debug("Saved manager #{ems.id} | Layer #{index}") end logger.debug("Saving manager #{ems.id}...Complete") end