dalhorinek

dalhorinek

Stopping child (GenServer) in DynamicSupervisor gracefully without restarting it

Hello.

I have a GenServer running as a child under DynamicSupervisor. The GenServer does something and using info status message I check it’s state and when the GenServer finished it’s job, I return

{:stop, :normal, state}

from it. And I want to stop the process, but the DynamicSupervisor restarts it again. I tried to send a message before returning the {:stop… } and in the handler of the message call terminate_child, but the supervisor seems to be faster restarting the child before terminating it.

I want the process to be supervised for error reasons, so when there is a problem, it restarts it, but I want to end gracefully when finished without restarting it.

What can I do or what’s best way how to handle such scenario?

Thanks in advance.

Marked As Solved

kokolegorille

kokolegorille

What child spec do You pass to dynamic supervisor to start your worker?

Here is one I use that does not imply worker restart…

    spec = %{
      id: name,
      start: {Worker, :start_link, [args]},
      restart: :temporary,
      type: :worker
    }

Also Liked

dalhorinek

dalhorinek

Hey, I’m using the Module child spec.

   DynamicSupervisor.start_child(
    Service.ServiceSupervisor,
    {Service.Manager, [id: id, opts: opts]}
  )

I think it’s the restart: option. now I see in the docs

:transient - the child process is restarted only if it terminates abnormally, i.e., with an exit reason other than :normal , :shutdown , or {:shutdown, term} .

This seems to be what I was looking for, thanks for the hint with restart: option!

kokolegorille

kokolegorille

I am using restart: :temporary because I delegate the monitoring task to another process… making my dynamic supervisor superdumb.

But I would use :transient as well in your case :slight_smile:

Where Next?

Popular in Questions Top

gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
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
JulienCorb
I am trying to implement my new.html.eex file to create new posts on my website. new.html.eex: <h1>Create Post</h1> <%= ...
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
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

Other popular topics Top

axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 48475 226
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42158 114
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
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
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
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

We're in Beta

About us Mission Statement