streamline Streamer pings

This commit is contained in:
stwf 2019-08-14 11:58:32 -04:00
parent 15ef521009
commit 574856ef01
1 changed files with 5 additions and 12 deletions

View File

@ -35,28 +35,21 @@ defmodule Pleroma.Web.Streamer do
end
def init(args) do
spawn(fn ->
# 30 seconds
Process.sleep(@keepalive_interval)
GenServer.cast(__MODULE__, %{action: :ping})
end)
Process.send_after(self(), %{action: :ping}, @keepalive_interval)
{:ok, args}
end
def handle_cast(%{action: :ping}, topics) do
Map.values(topics)
def handle_info(%{action: :ping}, topics) do
topics
|> Map.values()
|> List.flatten()
|> Enum.each(fn socket ->
Logger.debug("Sending keepalive ping")
send(socket.transport_pid, {:text, ""})
end)
spawn(fn ->
# 30 seconds
Process.sleep(@keepalive_interval)
GenServer.cast(__MODULE__, %{action: :ping})
end)
Process.send_after(self(), %{action: :ping}, @keepalive_interval)
{:noreply, topics}
end