Fl4m3Ph03n1x
Start Application dependencies before main Applciation is started
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:
Questions
How can I fix this?
Marked As Solved
LostKobrakai
with {:ok, pid} <- Supervisor.start_link(children, opts) do
{:ok, things} = MyDependency.list_things()
{:ok, pid}
end
You need to start the supervisor (and therefore its children) before you can expect the children to run.
2
Also Liked
derek-zhou
Shouldn’t it be:
Supervisor.start_link(children, opts)
{:ok, things} = MyDependency.list_things()
1
Popular in Questions
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
Hi there, I'm working through my first release with elixir/phoenix. I've built a release with distillery and found that it crashes when I...
New
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
Hey,
I have a NanoPi-M3 and try to install Elixir on their Ubuntu image. I followed the Raspberry Pi installation instructions from the ...
New
I have a User schema with a :from_id field set to type :string:
defmodule TweetBot.Repo.Migrations.CreateUsers do
use Ecto.Migration
...
New
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
After calling mix ecto.create I get this error:
17:00:32.162 [error] GenServer #PID<0.412.0> terminating
** (Postgrex.Error) FATAL...
New
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
Hi,
I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
Other popular topics
Manning 2016 Halloween weekend sale via Deal of the Day
Friday, October 28 - Half off all MEAPs - code WM102816LT
Saturday, October 29 ...
New
In Ruby, I can go:
User.find_by(email: "foobar@email.com").update(email: "hello@email.com")
How can I do something similar in Elixir? ...
New
Credo is smart enough to check for (something like) this:
assert length(the_list) == 0
with this response:
Checking if an enum is empt...
New
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
Using vs code and installed ElixirLS: support and debugger.
And I got an error popped up on start up says
Failed to run ‘elixir’ comma...
New
Hi,
I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
After calling mix ecto.create I get this error:
17:00:32.162 [error] GenServer #PID<0.412.0> terminating
** (Postgrex.Error) FATAL...
New
I will often find my self writing things similar to:
case some_value do
nil -> something()
"" -> something()
_ -> someth...
New
Hi everyone!
I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New







