I'm working on implementing a supervisor for the first time and I'm running into issues that I can't figure out from the documentation. Specifically, when I try to start my process using SlowRamp.flood
I get {:error, {:invalid_child_spec, []}}
.
This is a very simple application and was made using mix new slow_ramp --sup.
The main file in ./lib/slow_ramp.ex
is:
defmodule SlowRamp do
use Application
# See http://elixir-lang.org/docs/stable/elixir/Application.html
# for more information on OTP Applications
def start(_type, _args) do
import Supervisor.Spec, warn: false
children = [
worker(SlowRamp.Flood, [])
]
# See http://elixir-lang.org/docs/stable/elixir/Supervisor.html
# for other strategies and supported options
opts = [strategy: :one_for_one, name: SlowRamp.Supervisor]
Supervisor.start_link(children, opts)
end
def flood do
Supervisor.start_child(SlowRamp.Supervisor, [])
end
end
My child function / file is in ./lib/SlowRamp/flood.ex
and looks like this:
defmodule SlowRamp.Flood do
def start_link do
Task.start_link(fn -> start end)
end
defp start do
receive do
{:start, host, caller} ->
send caller, System.cmd("cmd", ["opt"])
end
end
end
Any help would be very much appreciated. Thanks!
The problem is on
Supervisor.start_child(SlowRamp.Supervisor, [])
You need a valid child specification, like:
def flood do
import Supervisor.Spec
Supervisor.start_child(SlowRamp.Supervisor, worker(SlowRamp.Flood, [], [id: :foo]))
end
Thats the reason its telling that the child spec is invalid
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With