Hello Experts,
I am just starting to play with Supervisors and I have created the Project using mix new podder --sup
I get the Following error when I try to Invoke a Process using the Dynamic Supervisor.
This is my code.
I am using Elixir 1.7.3.
Applicaiton.ex
defmodule Podder.Application do
# See https://hexdocs.pm/elixir/Application.html
# for more information on OTP Applications
@moduledoc false
use Application
def start(_type, _args) do
# List all child processes to be supervised
children = [
# Starts a worker by calling: Podder.Worker.start_link(arg)
# {Podder.Worker, arg},
%{
id: Podder.DynamicSupervisor,
start: {Podder.DynamicSupervisor, :start_link, []}
}
]
# See https://hexdocs.pm/elixir/Supervisor.html
# for other strategies and supported options
opts = [strategy: :one_for_one, name: Podder.DynamicSupervisor]
Supervisor.start_link(children, opts)
end
end
Supervisor
defmodule Podder.DynamicSupervisor do
use DynamicSupervisor
def start_link() do
DynamicSupervisor.start_link(__MODULE__, :ok, name: __MODULE__)
end
@doc """
Server Side
"""
def init(_arg) do
DynamicSupervisor.init(strategy: :one_for_one)
end
def start_work do
{:ok, pid} = start_podcast_server
end
defp start_podcast_server do
spec = %{id: Podder, start: {Podder, :start_link, []}}
DynamicSupervisor.start_child(__MODULE__, spec)
end
end
GenServer
defmodule Podder do
use GenServer
@moduledoc """
Documentation for Podder.
"""
@doc """
Hello world.
## Examples
iex> Podder.hello()
:world
"""
def init(state) do
{:ok, state}
end
def handle_call(:fetch, _from, state) do
new_state = Map.put(state, "fetched", 1)
{:reply, new_state, new_state}
end
def handle_call(:get_state, _from, state) do
{:reply, state, state}
end
@doc """
Client Implementation
"""
def start_link(state) do
GenServer.start_link(__MODULE__, state)
end
def fetch_episodes(pid) do
GenServer.call(pid, :fetch)
end
def get_episodes(pid) do
GenServer.call(pid, :get_state)
end
end
I am trying this from iex
iex(4)> Podder.DynamicSupervisor.start_work
** (MatchError) no match of right hand side value: {:error, {:invalid_child_spec, {{Podder, :start_link, []}, :permanent, 5000, :worker, [Podder]}}}
(podder) lib/podcastsupervisor.ex:16: Podder.DynamicSupervisor.start_work/0
iex(4)>