kgrvamsi
Hello Everyone
I’m working on a project which needs to use dynamic supervisor to support creating genserver based workers .
The code today can fork/spawn a worker and get attached to the parent dynamic supervisor but when i want to terminate i still see the process as part of the dynamic supervisor process.
Here is the code on the same
Dynamic supervisor code
defmodule Testing.WorkerSupervisor do
@moduledoc """
Worker Supervisor to support dynamic workers
"""
use DynamicSupervisor
require Logger
def start_link(_) do
Logger.debug("Starting the Worker Supervisor")
DynamicSupervisor.start_link(__MODULE__, [], name: __MODULE__)
end
@impl true
def init(_) do
DynamicSupervisor.init(strategy: :one_for_one)
end
def start_task_worker(conn_id) do
spec = {Testing.ConnectionWorker, %{conn_id: conn_id}}
DynamicSupervisor.start_child(__MODULE__, spec)
end
def terminate_task_worker(pid) do
Logger.info("Terminating the Worker")
case DynamicSupervisor.terminate_child(__MODULE__, pid) do
:ok ->
Logger.info("Worker Terminated Successfully")
{:error, _} ->
Logger.info("PID not found")
end
end
end
The Processcheck worker who is part of the main supervisor i have this code
defmodule Testing.ConnectionWorker do
@moduledoc false
use GenServer, restart: :transient
state = %{
conn_info: %{
running: [%{
pid: "pid_id",
conn_name: "new worker"
}]
}
}
Enum.each(diff, fn conn ->
Enum.each(conn_info.running, fn run ->
if conn == run.conn_name do
IO.inspect(run.pid)
Testing.WorkerSupervisor.terminate_task_worker(run.pid)
end
end)
end)
When i see the process association with :observer.start i still see the worker attached to the Dynamic supervisor.
Am i doing the implementation wrong here?
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #security










Showing Posts 1 to 6- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
kokolegorille
Hello welcome,
Try to change this…
… to test if it restarts or not (it should never restart). If not, it means on terminate_child, the worker does not stop with normal status, and so it is restarted because of transient.
BTW I usually stop GenServer from within, with a specific message, or under some conditions, but not from the supervisor itself, and not with terminate_child().
kgrvamsi
Hi @kokolegorille thanks for your response and just to my knowledge want to know what is the difference between the Dynamic Supervisor terminating its child vs child terminating it self over a call?
and also checking on your suggestion that terminating the child from the genserver it self so was checking around some example for it and saw this
Is this what you are recommending and any directions on how to fetch the child process pid in the supervisor and send a call to the Genserver to stop?
kokolegorille
I always use DynamicSupervisor with Registry to help finding those workers by name.
kgrvamsi
@kokolegorille i’m using the ets tables and saving the genserver pid and the name associated to it and when i’m trying to kill it i’m sending a call to the genserver stop function to shutdown the process in normal mode.
Please advice if i’m doing it in the right way.
kokolegorille
The code is ok for stoping the GenServer, althought You might also use a cast instead of call.
The registry is ets based, no real need to duplicate it’s functionality by hand.
kgrvamsi
@kokolegorille thanks for the reply … your guidance is really helping me and making me love elixir more .
Here is the something i made a change as per your suggestions
Infact i’m not directly using the ets table but using this library which is kinda wrapper on top of ETS ({:ets, “~> 0.7.3”}) but i will take your suggestions on using registry.