Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README_refresh_timer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Refresh Timer Implementation Complete
26 changes: 25 additions & 1 deletion lib/symphony_elixir_web/live/dashboard_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ defmodule SymphonyElixirWeb.DashboardLive do

alias SymphonyElixirWeb.{Endpoint, ObservabilityPubSub, Presenter}
@runtime_tick_ms 1_000
@countdown_tick_ms 1_000

@impl true
def mount(_params, _session, socket) do
Expand All @@ -15,10 +16,12 @@ defmodule SymphonyElixirWeb.DashboardLive do
|> assign(:payload, load_payload())
|> assign(:now, DateTime.utc_now())
|> assign(:expanded, MapSet.new())
|> assign(:refresh_countdown_seconds, div(@runtime_tick_ms, 1000))

if connected?(socket) do
:ok = ObservabilityPubSub.subscribe()
schedule_runtime_tick()
schedule_countdown_tick()
end

{:ok, socket}
Expand All @@ -27,7 +30,21 @@ defmodule SymphonyElixirWeb.DashboardLive do
@impl true
def handle_info(:runtime_tick, socket) do
schedule_runtime_tick()
{:noreply, assign(socket, :now, DateTime.utc_now())}

{:noreply,
socket
|> assign(:payload, load_payload())
|> assign(:now, DateTime.utc_now())
|> assign(:refresh_countdown_seconds, div(@runtime_tick_ms, 1000))}
end

@impl true
def handle_info(:countdown_tick, socket) do
current_countdown = Map.get(socket.assigns, :refresh_countdown_seconds, 0)
new_countdown = max(current_countdown - 1, 0)

schedule_countdown_tick()
{:noreply, assign(socket, :refresh_countdown_seconds, new_countdown)}
end

@impl true
Expand Down Expand Up @@ -82,6 +99,9 @@ defmodule SymphonyElixirWeb.DashboardLive do
<span class="status-badge-dot"></span>
Offline
</span>
<span class="status-badge status-badge-refresh">
Refreshes in <%= @refresh_countdown_seconds %>s
</span>
</div>
</div>
</header>
Expand Down Expand Up @@ -388,6 +408,10 @@ defmodule SymphonyElixirWeb.DashboardLive do
Process.send_after(self(), :runtime_tick, @runtime_tick_ms)
end

defp schedule_countdown_tick do
Process.send_after(self(), :countdown_tick, @countdown_tick_ms)
end

defp pretty_value(nil), do: "n/a"
defp pretty_value(value), do: inspect(value, pretty: true, limit: :infinity)
end
6 changes: 6 additions & 0 deletions priv/static/dashboard.css
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,12 @@ pre,
display: none;
}

.status-badge-refresh {
background: var(--accent-soft);
border-color: rgba(197, 160, 99, 0.20);
color: var(--accent-ink);
}

/* ── Metric cards ──────────────────────────────────────────────── */

.metric-grid {
Expand Down