Background
I am trying to ensure an application’s dependency is started before the main application is, whilst also having said dependency as part of the Supervision Tree (as a child).
Problem
Currently I have this in application.ex
:
children = [
Telemetry,
{Phoenix.PubSub, name: PubSub},
Endpoint,
MyDependency
]
{:ok, things} = MyDependency.list_things()
IO.inpsect(things, label: "THINGS")
opts = [strategy: :one_for_one, name: WebInterface.Supervisor]
Supervisor.start_link(children, opts)
end
However, MyDependency.list_things()
crashes with:
[notice] Application web_interface exited: exited in: WebInterface.Application.start(:normal, [])
** (EXIT) exited in: GenServer.call(MyDependency.Runtime.Worker, :list_things, 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 understand this happens because the MyDependency
dependency is not started, and thus I cannot call it.
Research
I tried adding this dependency to extra_applications
, but to no avail:
def application do
[
mod: {WebInterface.Application, []},
extra_applications: [:logger, :runtime_tools, :my_dependency]
]
end
I also read the docs for the Application start
function, hoping to find some way to defer the start of my main app to a later stage, but I couldn’t find it:
https://hexdocs.pm/elixir/Application.html#c:start/2
Questions
How can I fix this?