Raxol.Core.ErrorRecovery.DependencyGraph (Raxol v2.0.1)

View Source

Manages dependency relationships between components for intelligent recovery.

This module builds and maintains a dependency graph that helps determine the optimal order for restarting components and implementing cascading failure prevention strategies.

Features

  • Dependency relationship mapping
  • Restart order optimization
  • Circular dependency detection
  • Fallback strategy configuration
  • Critical path analysis

Usage

# Build dependency graph from child specs
graph = DependencyGraph.build([
  {DatabaseWorker, []},
  {CacheWorker, [depends_on: [:database_worker]]},
  {APIWorker, [depends_on: [:cache_worker, :database_worker]]}
])

# Get restart order for a component
restart_order = DependencyGraph.get_restart_order(graph, :api_worker)

Summary

Functions

Build a dependency graph from child specifications.

Get all nodes that would be affected by the failure of a given node.

Get the dependencies for a given node.

Get the dependents (nodes that depend on this one) for a given node.

Get the fallback strategy for a node.

Get performance impact estimate for restarting a node.

Get the optimal restart order for a given node and its dependencies.

Get the restart strategy for a node.

Check if a node is on a critical path.

Determine if restarting a node would cause cascading restarts.

Types

dependency_graph()

@type dependency_graph() :: %Raxol.Core.ErrorRecovery.DependencyGraph{
  critical_paths: term(),
  edges: term(),
  fallback_strategies: term(),
  nodes: term(),
  restart_strategies: term()
}

fallback_strategy()

@type fallback_strategy() ::
  :disable
  | {:fallback_module, module()}
  | {:notification, String.t()}
  | :graceful_degradation

node_id()

@type node_id() :: atom() | term()

node_info()

@type node_info() :: %{
  id: node_id(),
  module: module(),
  priority: integer(),
  critical: boolean(),
  fallback_strategy: fallback_strategy()
}

restart_strategy()

@type restart_strategy() ::
  :wait_for_dependencies
  | :restart_with_dependencies
  | :independent
  | :graceful_degradation

Functions

build(children_specs)

Build a dependency graph from child specifications.

get_affected_nodes(graph, failed_node_id)

Get all nodes that would be affected by the failure of a given node.

get_dependencies(graph, node_id)

Get the dependencies for a given node.

get_dependents(graph, node_id)

Get the dependents (nodes that depend on this one) for a given node.

get_fallback_strategy(graph, node_id)

Get the fallback strategy for a node.

get_restart_impact(graph, node_id)

Get performance impact estimate for restarting a node.

get_restart_order(graph, node_id)

Get the optimal restart order for a given node and its dependencies.

get_restart_strategy(graph, node_id)

Get the restart strategy for a node.

is_critical?(graph, node_id)

Check if a node is on a critical path.

would_cascade?(graph, node_id)

Determine if restarting a node would cause cascading restarts.