From 05815a0f8befa17aeaedacbea19af1dacdb4f902 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Sat, 21 Jun 2025 22:05:31 -0500 Subject: [PATCH] add deployed timestamp --- Dockerfile | 3 ++ lib/aprs_web/live/map_live/index.ex | 62 ++++++++++++++++++++++++++++- 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index d7ed308..e4dd0d2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -53,6 +53,9 @@ RUN apt-get update -y && \ 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" +# Set deployment timestamp to current time during build +ENV DEPLOYED_AT=$(date -u +"%Y-%m-%dT%H:%M:%SZ") + # Set working directory WORKDIR "/app" RUN chown nobody /app diff --git a/lib/aprs_web/live/map_live/index.ex b/lib/aprs_web/live/map_live/index.ex index 2e732a5..89744e2 100644 --- a/lib/aprs_web/live/map_live/index.ex +++ b/lib/aprs_web/live/map_live/index.ex @@ -17,6 +17,29 @@ defmodule AprsWeb.MapLive.Index do @impl true def mount(_params, _session, socket) do + if connected?(socket) do + # Subscribe to packet updates + Phoenix.PubSub.subscribe(Aprs.PubSub, "packets") + Phoenix.PubSub.subscribe(Aprs.PubSub, "bad_packets") + + # Schedule periodic cleanup of old packets + Process.send_after(self(), :cleanup_old_packets, 60_000) + end + + # Get deployment timestamp from environment variable or use current time as fallback + 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) socket = assign_defaults(socket, one_hour_ago) @@ -29,7 +52,26 @@ defmodule AprsWeb.MapLive.Index do maybe_start_geolocation(socket) end - {:ok, socket} + {:ok, + assign(socket, + map_ready: false, + map_bounds: nil, + map_center: %{lat: 39.8283, lng: -98.5795}, + map_zoom: 4, + visible_packets: %{}, + historical_packets: %{}, + overlay_callsign: "", + trail_duration: "1", + historical_hours: "1", + packet_age_threshold: 3600, + slideover_open: true, + replay_active: false, + replay_start_time: nil, + replay_end_time: nil, + replay_current_time: nil, + replay_speed: 1, + deployed_at: deployed_at + )} end @spec assign_defaults(Socket.t(), DateTime.t()) :: Socket.t() @@ -906,6 +948,24 @@ defmodule AprsWeb.MapLive.Index do View Bad Packets + + +
+
+ + + + Deployed: +
+
+ {Calendar.strftime(@deployed_at, "%Y-%m-%d %H:%M UTC")} +
+
"""