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
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
New
Kia ora,
We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
Hello,
I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter).
The diffic...
New
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
Other Trending Topics
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
There are three potential reasons for members of this forum to have a look at https://vutuv.de
You are tired or annoyed of LinkedIn.
Yo...
New
ICal is a library for interacting with iCalendar data. It parses iCalendars into typed Elixir structs via ICal.from_ics, and can prepare ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #ai
- #phoenix_html
- #elixirconf-us
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming











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.