Paperelectron

Paperelectron

Wiring up a Dashboard for Dynamic Supervised GenServers

Hey all, I’m looking to get some general advice on how to wire up a bunch of Dynamic Supervised GenServers, named via the registry, to a LiveView frontend. I’d like them to be able to broadcast updates about what they are doing, and have the individual list members update.

I’m currently using Registry.select to get the list of servers, but I’m unsure about how to go about handling adding and removing new named Servers as they come up. I’d rather not put any of the data about these servers in the DB, as they are meant to be pretty ephemeral.

My gut feeling is I should have a separate GenServer that handles Subscriptions and the overarching state of the list that I can then use LiveView to call into/receive messages from. Would I use this GenServer to handle the creation/deletion of the child Servers? Use Monitors? This feels like I’m stepping on the toes of the Registry a bit? What happens when I want to cluster this?

Basically, this is the type of problem I want to solve generally using Elixir, and I don’t yet have enough experience to know the correct way to approach it.

Not looking for any detailed code just a bit of a discussion on how those with more experience would architect something like this.

Marked As Solved

schneebyte

schneebyte

pg — OTP 29.0.2 (kernel 11.0.2) might be able to handle that out of the box.

You can monitor scopes/groups and get notifications when they join/leave (spawn/die).
Group names can be any Erlang term, so with the right scope/group structure it can be very flexible.

Maybe the GenServers could push state updates instead of polling them for an update.
Have the liveview process register to one or multiple groups {:i_want_notifications, :topic1} and the individual GenServers can send state updates to all members of that group.

Also Liked

al2o3cr

al2o3cr

A fairly common pattern would combine an initial call to Registry with PubSub:

  • the LiveView fetches the “current list” from the registry
  • it also subscribes to a “new server started” pubsub topic (and probably a “server ended”?)
  • when a server starts, it sends a pubsub notification of that

Adding things like clustering to the mix makes handling cases like “the whole NODE these servers were on went away”; you may need to include some kind of liveness-checking in your LiveView.

Where Next?

Popular in Questions Top

aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lists...
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: The documentation above suggests that while ...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New

Other popular topics Top

lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39297 209
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New

Latest on Elixir Forum

We're in Beta

About us Mission Statement