andzdroid

andzdroid

How to gather information from multiple processes?

I have a worker process that lives for some time and contains some state. Worker processes can be spawned from multiple processes, so there is no single source that is the “parent” of these workers.

I want to show a dashboard of all the worker processes that are running and some information from their state. I want to show this all in a liveview, preferably on page load or soon after, so preferably all in one go, not as a page that slowly populates from a stream of data.

What is the best way for my liveview to gather all this information living in different processes?

My current solution is for the workers to regularly report their state to a gen server that keeps track of the workers, and the liveview calls this tracker process on mount. The tracker also listens for the death of workers so it can remove their info. Is there a better way to do this? This tracker feels like a single point of failure, and is also duplicating all the state that is already stored in the workers.

Marked As Solved

LostKobrakai

LostKobrakai

You can use Registry.select for fetching everything registered in the registry. There’s no explicit API for that given this can be rather expensive depending on the number of processes registered.

Also Liked

hst337

hst337

So all of these workers actually have a single parent :slight_smile:
What information are you gathering? You can use Registry as @LostKobrakai pointed out, or you can just use DynamicSupervisor.which_children/1 and then calling every process, querying information you need. The right decision depends on the information you’re gathering

hst337

hst337

How often do you query this info? How often does this subset of state change? Do you want to see changes to this state in live view automatically or only on user-initiated update?

Where Next?

Popular in Questions Top

bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
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
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
kostonstyle
Hi all I want to have a unix time, from the current time plus 1 hour. DateTime.now + 1 hour How to get it in elixir? Thanks
New
chewm
Hi guys, nice to meet you to the whole forum, I’m new here, I’m trying to configure visual studio code for elixir, right now the intellis...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
Mooodi
Given a string, how can I get access to its character by index? Enum.at("my_string", 2) doesn't work. Or rather, not char, but a substr...
New

Other popular topics Top

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
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
AstonJ
You’re a programmer, so you don’t need spoon feeding with the conventional drivel about “this is an integer.” No. You need to know what’s...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 35421 110
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
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
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
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New

We're in Beta

About us Mission Statement