janj

janj

Extending supervisor functionality: updating child restart parameters and publishing events

While working with Supervisors, I keep running into two pieces of functionality that are not supported: updating the restart parameters of child processes and subscribing to supervision events. I’m probably missing constraints that need to be met by supervisors, possibly performance, reliability or simplicity related. Could someone shed some light on the design considerations of supervisors so I can see what the impact would be of adding this functionality?
Below, I’ll illustrate where I think the additional functionality would be useful.

Updating child restart parameters
The state of some processes will be updated by users of the system, and losing that changed state could mean the system as a whole does not function correctly. In stead of keeping a copy of the state in another process (as proposed by Dave Thomas in Programming Elixir) and having the child process recover the state of its predecessor, you could update the parameters stored in the supervisor that are used to start the replacement process.

In practice, this would mean adding a function to the supervisor that directly updates the children field of the supervisor struct. You could limit this to only allow children to update their own restart parameters. By adding this functionality, the newly started child would start with the correct state, without having to rely on an external service to recover state from. Are there any drawbacks to this approach?

Subscribing to supervision events
When processes are dependent on each other, we can monitor them to be informed of their untimely demise. This, however, only tells you the process is gone, not which process replaced it (if any). Supervisors have this knowledge, and could inform other processes what happened. This would be especially useful when a lot of other processes rely on that process being around. :syn (a distributed process registry) supports something that is similar, but only reports on process crashes, as it won’t know either which process replaced the crashed one. Have others attempted to publish these events in their supervisors, or is there something wrong with this approach that I’m not seeing?

Where Next?

Popular in Chat/Questions Top

pdgonzalez872
Hi! In my quest of becoming the best Elixir dev I can be, I saw one aspect in my career that I’d like to improve upon. This is language...
New
ariandanim
Hello all, I am still learning Elixir, then go into Phoenix, i am try search in google but find the programming phoenix 1.4, another for...
New
wolfiton
Question: Can someone recommend me some good resources on learning performance for phoenix elixir applications and a design pattern I sh...
New
wolfiton
Hi everyone, How can i retrieve the name from a structure like this? %{"id" => "1570", "name" => "Croque Monsieur"} My test loo...
New
lc0815
hello from a real frustrated newbe… I’m reading this article Full-Stack React With Phoenix (Chapter 3 | Introduction to Phoenix) by mich...
New
g5becks
Hello everyone. So I just got done reading all of the introduction to Elixir and working through the basics of the language. I am not new...
New
Allyedge
Hey, I want to learn Elixir OTP and I wanted to know if there are any good resources that teach it. I found some web pages, but none of t...
New
asfand
I am Asfandyar from Pakistan. This is my first time to the forum. I develop PHP websites using CodeIgniter, which is super easy to learn...
New
pdgonzalez872
Do we have a list of academic/research papers: about Elixir/Erlang? that use Elixir/Erlang? about the Beam? If so, could you please po...
New
Twfo326
As a novice dev I’m trying to keep the curriculum as lean as possible. My requirements are modest: build simple CRUD apps with Phoenix...
New

Other popular topics Top

lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
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
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
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
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