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
Hi,
I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
Lets say I have map like this fetching from my database
%{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
In templates/appointment/index.html.eex:
<%= for appointment <- @appointments do %>
<tr>
<td><%= appoi...
New
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
Hello all!
I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
I am trying to run a deploy with docker and I successfully runned with this command:
docker build -t romenigld/blog-prod .
but when I t...
New
Other popular topics
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine)
This is a plugin that adds support for Elixir to JetBrains IntelliJ...
New
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum.
...
New
If I have a post route which an argument:
post /my_post_route/:my_param1, MyController.my_post_handler
How would get the post params ...
New
Hello everyone,
Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
i’m a new one to elixir
which editor can i use
vs code? or atom?
Thanks! :smiley:
New
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









