runner code refactor, frontend papercuts
Some checks failed
CI/CD Pipeline / build (push) Failing after 4s
Some checks failed
CI/CD Pipeline / build (push) Failing after 4s
This commit is contained in:
34
lib/elixir_ai/chat_runner/liveview_session.ex
Normal file
34
lib/elixir_ai/chat_runner/liveview_session.ex
Normal file
@@ -0,0 +1,34 @@
|
||||
defmodule ElixirAi.ChatRunner.LiveviewSession do
|
||||
require Logger
|
||||
|
||||
def handle_call(:get_liveview_pids, _from, state) do
|
||||
{:reply, Map.keys(state.liveview_pids), state}
|
||||
end
|
||||
|
||||
def handle_call({:register_liveview_pid, liveview_pid}, _from, state) do
|
||||
ref = Process.monitor(liveview_pid)
|
||||
{:reply, :ok, %{state | liveview_pids: Map.put(state.liveview_pids, liveview_pid, ref)}}
|
||||
end
|
||||
|
||||
def handle_call({:deregister_liveview_pid, liveview_pid}, _from, state) do
|
||||
case Map.pop(state.liveview_pids, liveview_pid) do
|
||||
{nil, _} ->
|
||||
{:reply, :ok, state}
|
||||
|
||||
{ref, new_pids} ->
|
||||
Process.demonitor(ref, [:flush])
|
||||
{:reply, :ok, %{state | liveview_pids: new_pids}}
|
||||
end
|
||||
end
|
||||
|
||||
def handle_down(ref, pid, _reason, state) do
|
||||
case Map.get(state.liveview_pids, pid) do
|
||||
^ref ->
|
||||
Logger.info("ChatRunner #{state.name}: LiveView #{inspect(pid)} disconnected")
|
||||
{:noreply, %{state | liveview_pids: Map.delete(state.liveview_pids, pid)}}
|
||||
|
||||
_ ->
|
||||
{:noreply, state}
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user