Elixir: invalid_child_spec for the monitored process. I can not understand why

I am working on the implementation of a supervisor for the first time, and I am having problems that I cannot understand from the documentation. In particular, when I try to start my process using SlowRamp.flood , I get {:error, {:invalid_child_spec, []}} .

This is a very simple application and was created using the new version of slow_ramp --sup.

The main file in ./lib/slow_ramp.ex :

 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 ./lib/SlowRamp/flood.ex 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 greatly appreciated. Thanks!

+5
source share
1 answer

The problem is

 Supervisor.start_child(SlowRamp.Supervisor, []) 

You need a valid child specification, for example:

 def flood do import Supervisor.Spec Supervisor.start_child(SlowRamp.Supervisor, worker(SlowRamp.Flood, [], [id: :foo])) end 

That's why he says the child spec is not valid

+3
source

All Articles