Fl4m3Ph03n1x
Background
I am trying to understand the purpose of the application function in the mix.exs files we get, but I have some questions that need clarification.
Following is an example of said function:
def application do
[
extra_applications: [:logger],
mod: {FootbalInterface.Application, [http_port: 8080]}
]
end
Questions
-
Why do we need
extra_applications? I understand that in the past we needed to tellmixwhich applications to run on startup before our app was running. But these days,mixis pretty smart and it starts all needed applications before starting our own app. So why do we still have this value for Elixir 1.9? I think even:loggerstarts automatically so why do we have it there? -
Do we need
mod? I understand this tells mix the starting parameters for my app, but if I can simply useApplication.get_envin the files, then why do I need this? Will this allow me to start the application by passing values into the command line, likemix -S iex --args http_port: 4000or something like that?
Trending in Questions
Other Trending Topics
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
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixir-ls
- #ai
- #elixirconf-us
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming











Showing Posts 1 to 5- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
NobbZ
The return value of the
application/0callback in aMix.Projectis used to build the actual OTP-application manifest.Whether or not you need
:extra_applicationsand:modclearly depends on your use case.:extra_applicationsis required once you want to embed and start applications into your release that are part of elixir or erlang distribution. If you do not specify them, they won’t get embedded. They are added to the usually infered (since 1.4):applicationskey, which you shouldn’t set anymore since inference is in place.:modis required if you want an “active” application that has its own supervision tree. It actually tells the runtime how to start and stop the application.hauleth
:loggerIIRC starts “automatically” only in development (and in production it will start due to fact that this is commonly present in deps). However there are other applications that can be present in application and aren’t started by default,:inetis one of them (it is automatically started in Phoenix as one of it’s deps include that app).About
:modit say which is the “launching point” module in our application. Otherwise how would:initsupervisor know where is the main launching point of our application? There is no “convention” there.LostKobrakai
There are also a few more keys, which can be present in the returned data of
application/0: mix compile.app — Mix v1.20.2Fl4m3Ph03n1x
So, if I set
extra_applications: []and my application (which, let’s assume, has no deps) has arequire Loggersomewhere launches, will it crash?I understand that If my app doesn’t have a
require Loggerin its code, I can just remove that array and everything will work fine, independent of its dependencies. Is this correct?Like
:runtime_tools, right?So what I take from this is that in Elixir 1.9, we still have
:loggerin the array of extra applications because it is assumed we will use it somewhere in our app viarequire Logger. Would this assessment make sense?That makes sense. But why would someone bother passing starting parameters via
modinstead of just usingApplication.get_envin theapplication.exfile?Is there a special way to launch an app I am not aware of?
hauleth
No unless it will try to send message to the Logger process (so any logging will not work).
Probably yes as any dependency that uses
Loggershould handle that for you.Exactly.
Yes, this is done for user convenience. However I think that in future we should move
Loggermodules to Elixirstdliband make:loggerdummy application as we should move to Erlang’s:logger(which is in:kernelwhich is always started).I cannot find any, but I haven’t reviewed it more. Maybe there is option to overwrite such configuration or other stuff. Passing arguments via
:modcan also be useful in case of phase usages.Think about it like CLI options passed in systemd service file vs configuration file for such application.