aprs.me/lib/aprsme/deployment_notifier.ex
Graham McIntire a9827f245e
Some checks failed
Elixir CI / Build and test (push) Successful in 1m33s
Elixir CI / Dialyzer (push) Has been cancelled
Elixir CI / Build and Push Docker Image (push) Has been cancelled
fix: resolve all dialyzer warnings — unmatched returns, pattern mismatches, and Mix.Task PLT entries
2026-07-27 14:18:42 -05:00

42 lines
994 B
Elixir

defmodule Aprsme.DeploymentNotifier do
@moduledoc """
Notifies connected clients about deployment changes.
Called from the release module when a deployment is detected.
"""
use GenServer
require Logger
def start_link(opts \\ []) do
GenServer.start_link(__MODULE__, opts, name: __MODULE__)
end
@impl true
def init(_opts) do
_ =
if System.get_env("DEPLOYED_AT"),
do: Process.send_after(self(), :notify_deployment, 10_000)
{:ok, %{}}
end
@impl true
def handle_info(:notify_deployment, state) do
deployed_at = Aprsme.Release.deployed_at()
:ok = notify_deployment(deployed_at)
Logger.info("Deployment notification sent for timestamp: #{deployed_at}")
{:noreply, state}
end
@doc """
Notify about a new deployment immediately.
"""
def notify_deployment(deployed_at) do
Phoenix.PubSub.broadcast(
Aprsme.PubSub,
"deployment_events",
{:new_deployment, %{deployed_at: deployed_at}}
)
end
end