Debounce backfill dashboard updates to once per second

This commit is contained in:
Graham McIntire 2026-04-03 10:52:24 -05:00
parent 8d84bd2d18
commit 1c7c980cf4
No known key found for this signature in database
GPG key ID: F4ABF488E6029E59

View file

@ -34,7 +34,8 @@ defmodule MicrowavepropWeb.BackfillLive do
unprocessed: unprocessed,
db_stats: db_stats,
last_enqueued: nil,
enqueuing: false
enqueuing: false,
refresh_timer: nil
)}
end
@ -59,21 +60,33 @@ defmodule MicrowavepropWeb.BackfillLive do
end
def handle_info({:contact_status_changed, _data}, socket) do
{:noreply,
assign(socket,
unprocessed: count_unprocessed(),
db_stats: fetch_db_stats()
)}
{:noreply, schedule_refresh(socket)}
end
def handle_info({:oban_job_changed, _data}, socket) do
{:noreply, schedule_refresh(socket)}
end
def handle_info(:refresh_stats, socket) do
{:noreply,
assign(socket,
stats: fetch_stats(),
unprocessed: count_unprocessed()
unprocessed: count_unprocessed(),
db_stats: fetch_db_stats(),
refresh_timer: nil
)}
end
defp schedule_refresh(%{assigns: %{refresh_timer: ref}} = socket) when is_reference(ref) do
# Already scheduled, skip
socket
end
defp schedule_refresh(socket) do
ref = Process.send_after(self(), :refresh_stats, 1000)
assign(socket, refresh_timer: ref)
end
@enrichable [:pending, :failed]
defp enqueue_batch(limit) do