I have a phoenix where I’m working on Redix. So what I did to start this I added one more child and in the supervisor.
defmodule Gorm.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 = [
# Start the Ecto repository
Gorm.Repo,
# Start the endpoint when the application starts
GormWeb.Endpoint,
# Starts a worker by calling: Gorm.Worker.start_link(arg)
# {Gorm.Worker, arg},
Gorm.RedisPool
]
# See https://hexdocs.pm/elixir/Supervisor.html
# for other strategies and supported options
opts = [strategy: :one_for_one, name: Gorm.Supervisor]
Supervisor.start_link(children, opts)
end
# Tell Phoenix to update the endpoint configuration
# whenever the application is updated.
def config_change(changed, _new, removed) do
GormWeb.Endpoint.config_change(changed, removed)
:ok
end
end
And here is my redis_pool.ex file
defmodule Gorm.RedisPool do
use Supervisor
@redis_connection_params host: Application.get_env(:gorm, :redis_host),
password: Application.get_env(:gorm, :redis_password),
port: Application.get_env(:gorm, :redis_port),
database: Application.get_env(:gorm, :redis_database)
def start_link() do
GenServer.start_link(__MODULE__, [])
end
def init([]) do
pool_opts = [
name: {:local, :redix_poolboy},
worker_module: Redix,
size: 10,
max_overflow: 5,
]
children = [
:poolboy.child_spec(:redix_poolboy, pool_opts, @redis_connection_params)
]
supervise(children, strategy: :one_for_one, name: __MODULE__)
end
def command(command) do
:poolboy.transaction(:redix_poolboy, &Redix.command(&1, command))
end
def pipeline(commands) do
:poolboy.transaction(:redix_poolboy, &Redix.pipeline(&1, commands))
end
end
So when I try to run my server it’s giving me this error
Compiling 16 files (.ex)
Generated gorm app
[info] Running GormWeb.Endpoint with cowboy 2.7.0 at 0.0.0.0:4000 (http)
[info] Access GormWeb.Endpoint at http://localhost:4000
[info] Application gorm exited: Gorm.Application.start(:normal, []) returned an error: shutdown: failed to start child: Gorm.RedisPool
** (EXIT) an exception was raised:
** (UndefinedFunctionError) function Gorm.RedisPool.start_link/1 is undefined or private
(gorm) Gorm.RedisPool.start_link([])
(stdlib) supervisor.erl:379: :supervisor.do_start_child_i/3
(stdlib) supervisor.erl:365: :supervisor.do_start_child/2
(stdlib) supervisor.erl:349: anonymous fn/3 in :supervisor.start_children/2
(stdlib) supervisor.erl:1157: :supervisor.children_map/4
(stdlib) supervisor.erl:315: :supervisor.init_children/2
(stdlib) gen_server.erl:374: :gen_server.init_it/2
(stdlib) gen_server.erl:342: :gen_server.init_it/6
(stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
** (Mix) Could not start application gorm: Gorm.Application.start(:normal, []) returned an error: shutdown: failed to start child: Gorm.RedisPool
** (EXIT) an exception was raised:
** (UndefinedFunctionError) function Gorm.RedisPool.start_link/1 is undefined or private
(gorm) Gorm.RedisPool.start_link([])
(stdlib) supervisor.erl:379: :supervisor.do_start_child_i/3
(stdlib) supervisor.erl:365: :supervisor.do_start_child/2
(stdlib) supervisor.erl:349: anonymous fn/3 in :supervisor.start_children/2
(stdlib) supervisor.erl:1157: :supervisor.children_map/4
(stdlib) supervisor.erl:315: :supervisor.init_children/2
(stdlib) gen_server.erl:374: :gen_server.init_it/2
(stdlib) gen_server.erl:342: :gen_server.init_it/6
(stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
Can anyone help me here?