I’m new to Elixir and Phoenix and I’m trying to implement Cachex. I’m struggling to get this working. I added the dependency to my mix.exs
and I modified my application function so it references the Cachex app:
def application do
[
mod: {MyApp.Application, []},
extra_applications: [:logger, :runtime_tools],
applications: [:cachex]
]
end
deps.get downloaded the package and that all seems to be working.
In my application.ex, I have tried to add the appropriate block to the Supervisor.start_link:
def start(_type, _args) do
import Supervisor.Spec
# Define workers and child supervisors to be supervised
children = [
supervisor(MyApp.Repo, []),
supervisor(MyApp.Endpoint, []),
worker(Cachex, [:my_cache, []]),
]
opts = [strategy: :one_for_one, name: MyApp.Supervisor]
Supervisor.start_link(children, opts)
end
As soon as I try to run the server, I get an error:
mix phx.server
Compiling 16 files (.ex)
Generated my_app app
=INFO REPORT==== 12-Feb-2018::15:32:28 ===
application: logger
exited: stopped
type: temporary
** (Mix) Could not start application my_app: MyApp.Application.start(:normal, []) returned an error: shutdown: failed to start child: MyApp.Repo
** (EXIT) exited in: GenServer.call(Ecto.Registry, {:associate, #PID<0.367.0>, {MyApp.Repo, MyApp.Repo.Pool, [name: MyApp.Repo.Pool, otp_app: :my_app, repo: MyApp.Repo, timeout: 15000, pool_timeout: 5000, adapter: Ecto.Adapters.MySQL, username: "my_user", password: "xxxxx", database: "my_db", hostname: "my.host.tld", pool_size: 10, pool: DBConnection.Poolboy]}}, 5000)
** (EXIT) no process: the process is not alive or there's no process currently associated with the given name, possibly because its application isn't started
I’m not sure why it is choking. I can at least compile the app and start the server if I add :cachex to the “extra_applications” instead of to the “applications” bit. Can someone shed some light on this? Is it viable to use extra_applications instead?