lorecrafting
Phoenix.Tracker handle_diff unable to call Phoenix.Tracker.List
For some reason i’m getting this error:
[error] GenServer KioskTracker_shard10 terminating
** (stop) exited in: GenServer.call(KioskTracker_shard10, {:list, “room:kiosk”}, 5000)
** (EXIT) process attempted to call itself
It’s erroring out on the Phoenix.Tracker.list call.
What is the proper way to access the list of tracked connections within the handle_diff callback function of a Phoenix Tracker?
Thanks!
def handle_diff(diff, state) do
kiosks = Phoenix.Tracker.list(__MODULE__, "room:kiosk")
IO.puts("KIOSKS CONNECTED")
IO.inspect(kiosks)
for {topic, {joins, leaves}} <- diff do
for {key, meta} <- joins do
IO.puts("presence join: key \"#{key}\" with meta #{inspect(meta)}")
# This stuff might be for distributed system with more than one node, look into it later
# msg = {:join, key, meta}
# Phoenix.PubSub.direct_broadcast!(state.node_name, state.pubsub_server, topic, msg)
end
for {key, meta} <- leaves do
IO.puts("presence leave: key \"#{key}\" with meta #{inspect(meta)}")
# This stuff might be for distributed system with more than one node, look into it later
# msg = {:leave, key, meta}
# Phoenix.PubSub.direct_broadcast!(state.node_name, state.pubsub_server, topic, msg)
end
end
{:ok, state}
end
Blockquote
Marked As Solved
sb8244
The one thing to consider with handle_diff is that it will execute on every node in the cluster for a given change. This means that if there’s some logic you want to do once, it will actually run N times.
The Channel approach may work here (especially if intercepting handle_diff). You can execute code to check the kiosks and shut down in that case. I normally recommend Tracker, but Presence would actually fit pretty well if you’re intercepting handle_diff. It’s just tracker + broadcasting the diff to that topic.
Last Post!
vbroskas
How did you end up solving this issue? Im getting the same error when trying to call Phoenix.Tracker.list(tracker_name, topic) from either inside my handle_diff() callback or another module.
I thought of intercepting presence_diff in my channel, and each time there was a leave I could make a call to Phoenix.Tracker.list(). However Im finding that while intercepting prescence_diff it doesn’t seem to fire when the last person subscribed to a topic leaves (I assume this is because the last person leaving kills the presence for that topic)
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #elixirconf-us
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









