Make stats feed update automatically

This commit is contained in:
Claudio Ortolina
2024-11-04 12:22:23 +00:00
parent 7139e0ad8f
commit 065ca4bf7c
5 changed files with 42 additions and 2 deletions
+7
View File
@@ -14,11 +14,18 @@ defmodule LastFm.Feed do
def update(tracks) do
data = Enum.map(tracks, fn t -> {t.scrobbled_at_uts, t} end)
:ets.delete_all_objects(__MODULE__)
:ets.insert(__MODULE__, data)
Phoenix.PubSub.broadcast(LastFm.PubSub, "feed:update", %{tracks: data})
end
def all do
:ets.tab2list(__MODULE__)
|> Enum.reverse()
end
def subscribe do
Phoenix.PubSub.subscribe(LastFm.PubSub, "feed:update")
end
end