I have a DynamicSupervisor
with basic settings, I am starting a child GenServer as
Supervisor.start_child(Recording.WorkerStarter, %{
id: String.to_atom(detailed_camera.name),
camera: detailed_camera,
sleep: detailed_camera.sleep
})
and Terminating it as
name
|> Process.whereis()
|> case do
nil -> :not_found
pid -> DynamicSupervisor.terminate_child(__MODULE__, pid)
end
I want to catch its termination, as when I terminate this child, I want to Log something.
I have tested terminate/2
in Recording.WorkerStarter
but it won't get called.
I have tried handle_info({:DOWN, ref, :process, _, _}, state)
it wont work.
How I can catch Recording.WorkerStarter
termination?
UPDATE:
this is my worker
defmodule Recording.WorkerStarter do
use GenServer
require Logger
def start_link(opts) do
IO.inspect("Started Recording.WorkerStarter")
{id, opts} = Map.pop!(opts, :id)
GenServer.start_link(__MODULE__, opts, name: id)
end
def init(state) do
schedule_fetch_call(state.sleep)
{:ok, state}
end