Debounce backfill dashboard updates to once per second
This commit is contained in:
parent
8d84bd2d18
commit
1c7c980cf4
1 changed files with 20 additions and 7 deletions
|
|
@ -34,7 +34,8 @@ defmodule MicrowavepropWeb.BackfillLive do
|
||||||
unprocessed: unprocessed,
|
unprocessed: unprocessed,
|
||||||
db_stats: db_stats,
|
db_stats: db_stats,
|
||||||
last_enqueued: nil,
|
last_enqueued: nil,
|
||||||
enqueuing: false
|
enqueuing: false,
|
||||||
|
refresh_timer: nil
|
||||||
)}
|
)}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -59,21 +60,33 @@ defmodule MicrowavepropWeb.BackfillLive do
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_info({:contact_status_changed, _data}, socket) do
|
def handle_info({:contact_status_changed, _data}, socket) do
|
||||||
{:noreply,
|
{:noreply, schedule_refresh(socket)}
|
||||||
assign(socket,
|
|
||||||
unprocessed: count_unprocessed(),
|
|
||||||
db_stats: fetch_db_stats()
|
|
||||||
)}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_info({:oban_job_changed, _data}, socket) do
|
def handle_info({:oban_job_changed, _data}, socket) do
|
||||||
|
{:noreply, schedule_refresh(socket)}
|
||||||
|
end
|
||||||
|
|
||||||
|
def handle_info(:refresh_stats, socket) do
|
||||||
{:noreply,
|
{:noreply,
|
||||||
assign(socket,
|
assign(socket,
|
||||||
stats: fetch_stats(),
|
stats: fetch_stats(),
|
||||||
unprocessed: count_unprocessed()
|
unprocessed: count_unprocessed(),
|
||||||
|
db_stats: fetch_db_stats(),
|
||||||
|
refresh_timer: nil
|
||||||
)}
|
)}
|
||||||
end
|
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]
|
@enrichable [:pending, :failed]
|
||||||
|
|
||||||
defp enqueue_batch(limit) do
|
defp enqueue_batch(limit) do
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue