defmodule Pi.Plugin.Supervisor do @moduledoc "DynamicSupervisor for isolated project-local plugin workers." use DynamicSupervisor alias Pi.Plugin.Worker alias Pi.Supervisor.Install def start_link(opts \\ []) do DynamicSupervisor.start_link(__MODULE__, opts, name: __MODULE__) end def install, do: Install.ensure(__MODULE__) def start_plugin(module) when is_atom(module) do install() DynamicSupervisor.start_child(__MODULE__, Worker.child_spec(module)) end def stop_plugin(pid) when is_pid(pid) do DynamicSupervisor.terminate_child(__MODULE__, pid) end @impl true def init(_opts) do DynamicSupervisor.init(strategy: :one_for_one) end end