Class: InventoryRefresh::SaveCollection::TopologicalSort
- Defined in:
- lib/inventory_refresh/save_collection/topological_sort.rb
Class Method Summary collapse
-
.save_collections(ems, inventory_collections) ⇒ Object
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.
Methods inherited from Base
save_inventory_object_inventory
Class Method Details
.save_collections(ems, inventory_collections) ⇒ Object
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.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# 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 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 |