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

View Source

Enhanced supervisor with intelligent error recovery strategies.

This supervisor extends the standard OTP supervisor with:

  • Adaptive restart strategies based on error patterns
  • Context preservation across restarts
  • Dependency-aware restart ordering
  • Performance impact awareness
  • Self-healing mechanisms

Features

  • Smart restart strategies that adapt to error frequency
  • Graceful degradation when components repeatedly fail
  • Context preservation to maintain state across restarts
  • Integration with error pattern learning
  • Performance monitoring integration

Usage

children = [
  {MyWorker, [context_key: :worker1]},
  {AnotherWorker, [depends_on: [:worker1]]}
]

RecoverySupervisor.start_link(
  children: children,
  strategy: :adaptive_one_for_one,
  max_restarts: 5,
  max_seconds: 60
)

Summary

Functions

Returns a specification to start this module under a supervisor.

Get recovery statistics for monitoring.

Preserve context for a child before restart.

Manually trigger recovery for a specific child.

Enable or disable degradation mode.

Types

recovery_strategy()

@type recovery_strategy() ::
  :adaptive_one_for_one
  | :adaptive_one_for_all
  | :adaptive_rest_for_one
  | :circuit_breaker

restart_info()

@type restart_info() :: %{
  child_id: term(),
  timestamp: DateTime.t(),
  error: term(),
  restart_count: non_neg_integer(),
  recovery_time_ms: non_neg_integer()
}

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

get_recovery_stats(supervisor \\ __MODULE__)

Get recovery statistics for monitoring.

handle_child_exit(child_id, reason, state)

preserve_context(supervisor \\ __MODULE__, child_id, context)

Preserve context for a child before restart.

recover_child(supervisor \\ __MODULE__, child_id)

Manually trigger recovery for a specific child.

set_degradation_mode(supervisor \\ __MODULE__, enabled)

Enable or disable degradation mode.

start_link(opts)