Current section
Files
Jump to
Current section
Files
lib/supervisor.ex
defmodule YaloTestConversation.Supervisor do
@moduledoc """
Documentation for Supervisor.
"""
require Logger
use Supervisor
def start_link(_) do
Supervisor.start_link(__MODULE__, nil, name: :activity_supervisor)
end
def init(_) do
children = [
worker(YaloTestConversation.Worker, [], restart: :temporary)
]
opts = [strategy: :simple_one_for_one]
supervise(children, opts)
end
def start_worker(bot, messages, activity) do
Logger.info("HEY")
id = UUID.uuid4()
case Supervisor.start_child(:activity_supervisor, [bot, messages, activity, id]) do
{:error, {:already_started, _value}} ->
Logger.error("ALREADY STARTED")
result = Supervisor.stop(:activity_supervisor, :normal, :infinity)
Logger.info("#{inspect(result)}")
if result == :ok do
Supervisor.start_child(:activity_supervisor, [bot, messages, activity])
end
{:ok, pid} ->
IO.inspect("START")
IO.inspect(pid)
# ref = Process.monitor(pid)
# refs = Map.put(refs, ref, name)
# names = Map.put(names, name, pid)
# {:noreply, {names, refs}}
x ->
Logger.info("#{inspect(x)}")
end
# IO.inspect(Supervisor.which_children(:activity_supervisor))
end
end