lorecrafting
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
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
sb8244
This might be an XY problem. What are you looking to achieve?
Without knowing much about your use case, you could spawn the with that needs the list of kiosks. However, you can’t do that if you need it for the return of the handle diff (I have a hard time envisioning a use case for that)
lorecrafting
I think you are right, this may be an XY problem and I might just be banging my head with very limited knowledge in Elixir =D
The problem i’m trying to solve is to shut off the ability to place an order on a mobile app if the separate web kiosk is not open.
The way i’m trying to implement it is in the handle_diff callback, whoever ‘leaves’ the channel will have their mobile app ordering shut off via a feature flag platform (LaunchDarkly).
However, there may be two or three different kiosks up at the same time for the same tenant, and wanted it to shut off if only ALL of them were off. So i was going to retrieve the existing list or presence of connections and check if there are no other kiosks of the same tenant on the list.
Is handle_diff the proper place to write all this logic or should I put it in a different module?
Thanks!
lorecrafting
Hmm.. I’m trying to implement spawning another process and calling the Track function inside of it but I get this error:
Is it saying the second item in the tuple can’t be a string?
If I do Phoenix.Tracker.list(KioskTracker, “room:kiosk”) In iex it works, but that exact function doesn’t work in the spawning function.
Thanks again for the help while i’m diving straight into this world!
sb8244
I’m pretty sure that’s from the receive. The line number will tell you exactly
Regardless, you can’t block the receive like that. When I recommended a spawn, I was talking purely about for side effect code. If you want the tracker result as part of processing the diff, then I think you’re blocked.
What are you trying to do? I’m almost certain that you shouldn’t go down this path.
lorecrafting
I’ll take your advice and rethink the solution. I may need help with it as my knowledge is very limited.
Within the receive, or once I somehow have the list of connected kiosks, i wanted to make sure there aren’t any identical kiosks in the list to the one that just disconnected. This is solving for the case that there are two or more kiosks up that belong to the same tenant.
Only when all kiosks of the a specific tenant has disconnected, only then do I want to fire off instructions that turn off mobile ordering functionality.
So in the handle_diff i need two pieces of information:
So that I can check the list to see if there are any other kiosks out there belonging to the same tenant. If there aren’t, then i’ll fire off the instructions to shut off mobile ordering. If there is then do nothing.
Would the alternate solution be to send a message from the handle_diff to another process to handle all the logic?
Again, thanks!
lorecrafting
Yup you’re right, it errors out in the receive.
lorecrafting
Ah! I’ve uncommented out PhoenixPubSub.direct_broadcast! functions and an now trying to do the logic in the Channels. Going to play around with that and think this may be a better direction!
sb8244
The one thing to consider with
handle_diffis 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.lorecrafting
Awesome, thanks for guidance!
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 myhandle_diff()callback or another module.I thought of intercepting
presence_diffin my channel, and each time there was aleaveI could make a call toPhoenix.Tracker.list(). However Im finding that while interceptingprescence_diffit doesn’t seem to fire when the last person subscribed to a topic leaves (I assume this is because the last person leaving kills thepresencefor that topic)