Class: Servitor::ServiceGraphFlattener
- Inherits:
-
Object
- Object
- Servitor::ServiceGraphFlattener
- Defined in:
- lib/service/service_graph/service_graph_flattener.rb
Class Method Summary collapse
-
.flatten_to_startup_order(graph) ⇒ Object
Takes a service graph and returns the service configs in service startup order.
Class Method Details
.flatten_to_startup_order(graph) ⇒ Object
Takes a service graph and returns the service configs in service startup order. This means that services in the list depend only on other services that appear later in the list.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/service/service_graph/service_graph_flattener.rb', line 10 def flatten_to_startup_order(graph) nodes = [] remaining_nodes = graph.service_nodes.values while remaining_nodes.any? found = false remaining_nodes.dup.each do |node| if node.depends_on_nodes.none? { |depends_on_node| remaining_nodes.include?(depends_on_node) } found = true nodes << node remaining_nodes.delete(node) break end end raise CyclicDependencyError unless found end nodes end |