diff --git a/lib/microwaveprop_web/live/status_live.ex b/lib/microwaveprop_web/live/status_live.ex index db8e2cff..b75c03f9 100644 --- a/lib/microwaveprop_web/live/status_live.ex +++ b/lib/microwaveprop_web/live/status_live.ex @@ -25,6 +25,7 @@ defmodule MicrowavepropWeb.StatusLive do unprocessed = count_unprocessed() db_stats = fetch_db_stats() grid_tasks = fetch_grid_tasks_stats() + hrrr_point_tasks = fetch_hrrr_point_tasks_stats() {:ok, assign(socket, @@ -33,6 +34,7 @@ defmodule MicrowavepropWeb.StatusLive do unprocessed: unprocessed, db_stats: db_stats, grid_tasks: grid_tasks, + hrrr_point_tasks: hrrr_point_tasks, refresh_timer: nil )} end @@ -57,6 +59,7 @@ defmodule MicrowavepropWeb.StatusLive do unprocessed: count_unprocessed(), db_stats: fetch_db_stats(), grid_tasks: fetch_grid_tasks_stats(), + hrrr_point_tasks: fetch_hrrr_point_tasks_stats(), refresh_timer: nil )} end @@ -224,6 +227,49 @@ defmodule MicrowavepropWeb.StatusLive do } end + defp fetch_hrrr_point_tasks_stats do + Cache.fetch_or_store({__MODULE__, :hrrr_point_tasks_stats}, 2_000, fn -> + fetch_hrrr_point_tasks_stats_raw() + end) + end + + # Snapshot of the Rust hrrr-point-rs work queue (per-QSO HRRR batches, + # one row per valid_time). Same shape as grid_tasks_stats so the UI + # can render both in a single table. + defp fetch_hrrr_point_tasks_stats_raw do + running_count = + Repo.one( + from(t in "hrrr_fetch_tasks", + where: t.status == "running", + select: count(t.id) + ) + ) + + counts_by_status = + from(t in "hrrr_fetch_tasks", + where: t.status in ["queued", "failed"], + group_by: t.status, + select: {t.status, count(t.id)} + ) + |> Repo.all() + |> Map.new() + + done_1h = + Repo.one( + from(t in "hrrr_fetch_tasks", + where: t.status == "done" and t.completed_at > ago(1, "hour"), + select: count(t.id) + ) + ) + + %{ + running: running_count, + queued: Map.get(counts_by_status, "queued", 0), + failed: Map.get(counts_by_status, "failed", 0), + done_1h: done_1h + } + end + defp fetch_stats do Cache.fetch_or_store({__MODULE__, :stats}, 2_000, fn -> fetch_stats_raw() end) end @@ -515,7 +561,7 @@ defmodule MicrowavepropWeb.StatusLive do
-| {format_number(@grid_tasks.done_1h)} | +||||
| hrrr-point-rs | ++ <%= if @hrrr_point_tasks.running == 0 do %> + 0 + <% else %> + + + {@hrrr_point_tasks.running} + batches + + <% end %> + | +{format_number(@hrrr_point_tasks.queued)} | ++ <%= if @hrrr_point_tasks.failed > 0 do %> + {@hrrr_point_tasks.failed} + <% else %> + 0 + <% end %> + | +{format_number(@hrrr_point_tasks.done_1h)} | +