deployed at fix

This commit is contained in:
Graham McIntire 2025-06-21 22:13:56 -05:00
parent d2ec835fdd
commit 2a98013a96
No known key found for this signature in database
3 changed files with 77 additions and 35 deletions

View file

@ -54,7 +54,7 @@ RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen
ENV LANG="en_US.UTF-8" LANGUAGE="en_US:en" LC_ALL="en_US.UTF-8" ENV LANG="en_US.UTF-8" LANGUAGE="en_US:en" LC_ALL="en_US.UTF-8"
# Set deployment timestamp to current time during build # Set deployment timestamp to current time during build
ENV DEPLOYED_AT=$(date -u +"%Y-%m-%dT%H:%M:%SZ") RUN date -u +"%Y-%m-%dT%H:%M:%SZ" > /app/deployed_at.txt
# Set working directory # Set working directory
WORKDIR "/app" WORKDIR "/app"

View file

@ -6,11 +6,13 @@ defmodule Aprs.Release do
@app :aprs @app :aprs
def migrate do def migrate do
load_app() # Initialize deployment timestamp first
deployed_at = init()
require Logger
Logger.info("Deployment timestamp: #{deployed_at}")
for repo <- repos() do # Run migrations
{:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :up, all: true)) {:ok, _, _} = Ecto.Migrator.with_repo(Aprs.Repo, &Ecto.Migrator.run(&1, :up, all: true))
end
end end
def rollback(repo, version) do def rollback(repo, version) do
@ -25,4 +27,39 @@ defmodule Aprs.Release do
defp load_app do defp load_app do
Application.load(@app) Application.load(@app)
end end
@doc """
Initialize release-specific configuration.
This is called during application startup.
"""
def init do
# Read deployment timestamp from file
deployed_at = read_deployment_timestamp()
# Add to application config
Application.put_env(:aprs, :deployed_at, deployed_at)
deployed_at
end
@doc """
Get the deployment timestamp.
"""
def deployed_at do
Application.get_env(:aprs, :deployed_at) || DateTime.utc_now()
end
defp read_deployment_timestamp do
case File.read("/app/deployed_at.txt") do
{:ok, timestamp} ->
case DateTime.from_iso8601(String.trim(timestamp)) do
{:ok, datetime, _} -> datetime
_ -> DateTime.utc_now()
end
_ ->
# Fallback to current time if file doesn't exist
DateTime.utc_now()
end
end
end end

View file

@ -26,19 +26,8 @@ defmodule AprsWeb.MapLive.Index do
Process.send_after(self(), :cleanup_old_packets, 60_000) Process.send_after(self(), :cleanup_old_packets, 60_000)
end end
# Get deployment timestamp from environment variable or use current time as fallback # Get deployment timestamp from config (set during application startup)
deployed_at = deployed_at = Aprs.Release.deployed_at()
case System.get_env("DEPLOYED_AT") do
nil ->
# Fallback to current time if not set
DateTime.utc_now()
timestamp when is_binary(timestamp) ->
case DateTime.from_iso8601(timestamp) do
{:ok, datetime, _} -> datetime
_ -> DateTime.utc_now()
end
end
one_hour_ago = DateTime.add(DateTime.utc_now(), -3600, :second) one_hour_ago = DateTime.add(DateTime.utc_now(), -3600, :second)
@ -154,14 +143,18 @@ defmodule AprsWeb.MapLive.Index do
@impl true @impl true
def handle_event("bounds_changed", %{"bounds" => bounds}, socket) do def handle_event("bounds_changed", %{"bounds" => bounds}, socket) do
Logger.debug("handle_event bounds_changed: #{inspect(bounds)} vs current #{inspect(socket.assigns.map_bounds)}") Logger.debug(
"handle_event bounds_changed: #{inspect(bounds)} vs current #{inspect(socket.assigns.map_bounds)}"
)
handle_bounds_update(bounds, socket) handle_bounds_update(bounds, socket)
end end
@impl true @impl true
def handle_event("update_bounds", %{"bounds" => bounds}, socket) do def handle_event("update_bounds", %{"bounds" => bounds}, socket) do
Logger.debug("handle_event update_bounds: #{inspect(bounds)} vs current #{inspect(socket.assigns.map_bounds)}") Logger.debug(
"handle_event update_bounds: #{inspect(bounds)} vs current #{inspect(socket.assigns.map_bounds)}"
)
handle_bounds_update(bounds, socket) handle_bounds_update(bounds, socket)
end end
@ -325,7 +318,9 @@ defmodule AprsWeb.MapLive.Index do
west: bounds["west"] west: bounds["west"]
} }
Logger.debug("handle_bounds_update: new #{inspect(map_bounds)} vs current #{inspect(socket.assigns.map_bounds)}") Logger.debug(
"handle_bounds_update: new #{inspect(map_bounds)} vs current #{inspect(socket.assigns.map_bounds)}"
)
# Validate bounds to prevent invalid coordinates # Validate bounds to prevent invalid coordinates
if map_bounds.north > 90 or map_bounds.south < -90 or if map_bounds.north > 90 or map_bounds.south < -90 or
@ -351,7 +346,9 @@ defmodule AprsWeb.MapLive.Index do
@spec process_bounds_update(map(), Socket.t()) :: Socket.t() @spec process_bounds_update(map(), Socket.t()) :: Socket.t()
defp process_bounds_update(map_bounds, socket) do defp process_bounds_update(map_bounds, socket) do
Logger.debug("process_bounds_update: Loading historical packets for bounds #{inspect(map_bounds)}") Logger.debug(
"process_bounds_update: Loading historical packets for bounds #{inspect(map_bounds)}"
)
# Remove out-of-bounds packets and markers immediately # Remove out-of-bounds packets and markers immediately
new_visible_packets = new_visible_packets =
@ -385,22 +382,30 @@ defmodule AprsWeb.MapLive.Index do
end end
@impl true @impl true
def handle_info({:process_bounds_update, map_bounds}, socket), do: handle_info_process_bounds_update(map_bounds, socket) def handle_info({:process_bounds_update, map_bounds}, socket),
do: handle_info_process_bounds_update(map_bounds, socket)
def handle_info({:delayed_zoom, %{lat: lat, lng: lng}}, socket), do: handle_info_delayed_zoom(lat, lng, socket) def handle_info({:delayed_zoom, %{lat: lat, lng: lng}}, socket),
do: handle_info_delayed_zoom(lat, lng, socket)
def handle_info({:ip_location, %{lat: lat, lng: lng}}, socket), do: handle_info_ip_location(lat, lng, socket) def handle_info({:ip_location, %{lat: lat, lng: lng}}, socket),
do: handle_info_ip_location(lat, lng, socket)
def handle_info(:initialize_replay, socket), do: handle_info_initialize_replay(socket) def handle_info(:initialize_replay, socket), do: handle_info_initialize_replay(socket)
def handle_info(:cleanup_old_packets, socket), do: handle_cleanup_old_packets(socket) def handle_info(:cleanup_old_packets, socket), do: handle_cleanup_old_packets(socket)
def handle_info(:reload_historical_packets, socket), do: handle_reload_historical_packets(socket) def handle_info(:reload_historical_packets, socket),
do: handle_reload_historical_packets(socket)
def handle_info({:postgres_packet, packet}, socket), do: handle_info_postgres_packet(packet, socket) def handle_info({:postgres_packet, packet}, socket),
do: handle_info_postgres_packet(packet, socket)
def handle_info(%Phoenix.Socket.Broadcast{topic: "aprs_messages", event: "packet", payload: packet}, socket), def handle_info(
do: handle_info({:postgres_packet, packet}, socket) %Phoenix.Socket.Broadcast{topic: "aprs_messages", event: "packet", payload: packet},
socket
),
do: handle_info({:postgres_packet, packet}, socket)
# Private handler functions for each message type # Private handler functions for each message type