better process tracking for admin dashboard
Some checks failed
CI/CD Pipeline / build (push) Failing after 5s

This commit is contained in:
2026-03-20 12:07:16 -06:00
parent b2f53942a2
commit 6138d71d29
21 changed files with 910 additions and 106 deletions

View File

@@ -3,17 +3,33 @@ defmodule ElixirAi.ClusterSingleton do
require Logger
@sync_delay_ms 200
@retry_delay_ms 500
@singletons [ElixirAi.ConversationManager]
def start_link(opts), do: GenServer.start_link(__MODULE__, opts, name: __MODULE__)
def status, do: GenServer.call(__MODULE__, :status)
def configured_singletons, do: @singletons
def init(_opts) do
Process.send_after(self(), :start_singletons, @sync_delay_ms)
{:ok, :pending}
end
def handle_info(:start_singletons, _state) do
def handle_info(:start_singletons, state) do
if Node.list() == [] do
Logger.debug("ClusterSingleton: no peer nodes yet, retrying in #{@retry_delay_ms}ms")
Process.send_after(self(), :start_singletons, @retry_delay_ms)
{:noreply, state}
else
start_singletons()
{:noreply, :started}
end
end
defp start_singletons do
for module <- @singletons do
if singleton_exists?(module) do
Logger.debug(
@@ -37,10 +53,10 @@ defmodule ElixirAi.ClusterSingleton do
end
end
end
{:noreply, :started}
end
def handle_call(:status, _from, state), do: {:reply, state, state}
defp singleton_exists?(module) do
case Horde.Registry.lookup(ElixirAi.ChatRegistry, module) do
[{pid, _metadata} | _] when is_pid(pid) ->