Push map updates via PubSub when propagation scores are computed
This commit is contained in:
parent
4e2d74e21c
commit
321133c3cb
2 changed files with 3 additions and 5 deletions
|
|
@ -36,6 +36,7 @@ defmodule Microwaveprop.Workers.PropagationGridWorker do
|
||||||
case Propagation.upsert_scores(scores) do
|
case Propagation.upsert_scores(scores) do
|
||||||
{:ok, count} ->
|
{:ok, count} ->
|
||||||
Logger.info("PropagationGrid: upserted #{count} scores for #{valid_time}")
|
Logger.info("PropagationGrid: upserted #{count} scores for #{valid_time}")
|
||||||
|
Phoenix.PubSub.broadcast(Microwaveprop.PubSub, "propagation:updated", {:propagation_updated, valid_time})
|
||||||
:ok
|
:ok
|
||||||
|
|
||||||
error ->
|
error ->
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ defmodule MicrowavepropWeb.MapLive do
|
||||||
alias Microwaveprop.Propagation.BandConfig
|
alias Microwaveprop.Propagation.BandConfig
|
||||||
|
|
||||||
@default_band 10_000
|
@default_band 10_000
|
||||||
@refresh_interval_ms to_timeout(minute: 5)
|
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def mount(_params, _session, socket) do
|
def mount(_params, _session, socket) do
|
||||||
|
|
@ -15,7 +14,7 @@ defmodule MicrowavepropWeb.MapLive do
|
||||||
valid_time = Propagation.latest_valid_time()
|
valid_time = Propagation.latest_valid_time()
|
||||||
|
|
||||||
if connected?(socket) do
|
if connected?(socket) do
|
||||||
Process.send_after(self(), :refresh, @refresh_interval_ms)
|
Phoenix.PubSub.subscribe(Microwaveprop.PubSub, "propagation:updated")
|
||||||
end
|
end
|
||||||
|
|
||||||
{:ok,
|
{:ok,
|
||||||
|
|
@ -43,10 +42,8 @@ defmodule MicrowavepropWeb.MapLive do
|
||||||
end
|
end
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def handle_info(:refresh, socket) do
|
def handle_info({:propagation_updated, valid_time}, socket) do
|
||||||
scores = Propagation.latest_scores(socket.assigns.selected_band)
|
scores = Propagation.latest_scores(socket.assigns.selected_band)
|
||||||
valid_time = Propagation.latest_valid_time()
|
|
||||||
Process.send_after(self(), :refresh, @refresh_interval_ms)
|
|
||||||
|
|
||||||
socket =
|
socket =
|
||||||
socket
|
socket
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue