working on redundancy

This commit is contained in:
2026-03-06 16:37:31 -07:00
parent 8059048db2
commit 181c6ca84b
16 changed files with 282 additions and 29 deletions

View File

@@ -0,0 +1,31 @@
defmodule ElixirAi.ClusterSingleton do
use GenServer
@sync_delay_ms 200
@singletons [ElixirAi.ConversationManager]
def start_link(opts), do: GenServer.start_link(__MODULE__, opts, name: __MODULE__)
@impl true
def init(_opts) do
Process.send_after(self(), :start_singletons, @sync_delay_ms)
{:ok, :pending}
end
@impl true
def handle_info(:start_singletons, state) do
for module <- @singletons do
case Horde.DynamicSupervisor.start_child(ElixirAi.ChatRunnerSupervisor, module) do
{:ok, _pid} -> :ok
{:error, {:already_started, _pid}} -> :ok
{:error, :already_present} -> :ok
{:error, reason} ->
require Logger
Logger.warning("ClusterSingleton: failed to start #{inspect(module)}: #{inspect(reason)}")
end
end
{:noreply, :started}
end
end