I have this GenServer
which is adding a child as a worker.
def handle_info(:request, state) do schedule_fetch_call(state.sleep) ping_time_state = Map.put(state, :running, %{datetime: DateTime.utc_now()}) DynamicSupervisor.start_child(General.Supervisor, {Recording.Worker, ping_time_state}) {:noreply, ping_time_state} end
and In Recording.Worker
I am doing this.
defmodule Recording.Worker do use GenServer, restart: :transient def start_link(state), do: GenServer.start_link(__MODULE__, state) def init(state) do send(self(), :fetch_and_process) {:ok, state} end def handle_info(:fetch_and_process, state) do case make_jpeg_request(state.camera, state.running.datetime) do {:failed, _requested_at} -> {:noreply, state} {body, requested_at} -> %{datetime: requested_at} |> put_it_in_jpeg_bank(state.camera.name) # save_it_to_weed requested_at |> Calendar.strftime("#{state.camera.name}/snapshots/%Y/%m/%d/%H_%M_%S.jpg") |> Everjamer.post("http://localhost:8888/", body) #this part is broadcaster. Broadcasting.any_one_wacthing?(state.camera.name) |> Broadcasting.stream(state.camera.name, body, requested_at) {:stop, :normal, state} end end end
now even after the work is done and complete, Everjamer.post
and Broadcasting.stream
have done its work. the Phoenix Live Dashboard continues to show them in Process.
Is there any way to stop this behaviour? So when the work is done it just stop and end itself?
Or even in case of {:failed, re...}
what would be the suggested way to just turn this child process off so it won't appear in the process?
没有评论:
发表评论