Current section
Files
Jump to
Current section
Files
lib/ex_ai/feature_supervisor.ex
defmodule ExAI.FeatureSupervisor do
@moduledoc """
Supervises optional feature-specific supervisors based on config flags.
"""
use Supervisor
@feature_supervisors [
{:web_enabled, ExAI.WebSupervisor},
{:remote_execution_enabled, ExAI.RemoteExecutionSupervisor},
{:extism_enabled, ExAI.ExtismSupervisor},
{:delegate_cli_enabled, ExAI.DelegateCliSupervisor}
]
@spec start_link(keyword()) :: Supervisor.on_start()
def start_link(opts \\ []) do
Supervisor.start_link(__MODULE__, :ok, Keyword.put_new(opts, :name, __MODULE__))
end
@impl true
def init(:ok) do
children =
for {flag, name} <- @feature_supervisors, ExAI.feature_enabled?(flag) do
{DynamicSupervisor, strategy: :one_for_one, name: name}
end
Supervisor.init(children, strategy: :one_for_one)
end
end