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
logicmason
Hi there, I'm working through my first release with elixir/phoenix. I've built a release with distillery and found that it crashes when I...
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
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
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
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
jc00ke
Expanding on this topic: https://forum.elixirforum.net/t/map-typespec-question/19217 Let’s say I have a map with required and optional k...
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
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

Other popular topics Top

openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
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 record...
New
sergio
I couldn’t find any guides that worked well with Phoenix 1.6.0 and esbuild. I hope this helps people test the waters and eases you into t...
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New

We're in Beta

About us Mission Statement