Fl4m3Ph03n1x

Fl4m3Ph03n1x

Why do we use application function in mix.exs?

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

  1. Why do we need extra_applications? I understand that in the past we needed to tell mix which applications to run on startup before our app was running. But these days, mix is 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 :logger starts automatically so why do we have it there?

  2. Do we need mod? I understand this tells mix the starting parameters for my app, but if I can simply use Application.get_env in the files, then why do I need this? Will this allow me to start the application by passing values into the command line, like mix -S iex --args http_port: 4000 or something like that?

Marked As Solved

hauleth

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 Logger should handle that for you.

Exactly.

Yes, this is done for user convenience. However I think that in future we should move Logger modules to Elixir stdlib and make :logger dummy application as we should move to Erlang’s :logger (which is in :kernel which 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 :mod can 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.

Also Liked

NobbZ

NobbZ

The return value of the application/0 callback in a Mix.Project is used to build the actual OTP-application manifest.

Whether or not you need :extra_applications and :mod clearly depends on your use case.

:extra_applications is 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) :applications key, which you shouldn’t set anymore since inference is in place.

:mod is 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

hauleth

:logger IIRC 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, :inet is one of them (it is automatically started in Phoenix as one of it’s deps include that app).

About :mod it say which is the “launching point” module in our application. Otherwise how would :init supervisor know where is the main launching point of our application? There is no “convention” there.

LostKobrakai

LostKobrakai

There are also a few more keys, which can be present in the returned data of application/0: https://hexdocs.pm/mix/Mix.Tasks.Compile.App.html

Where Next?

Popular in Questions Top

jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
makeitrein
Hey all, just started picking up Elixir last week and am writing a scraper as a learning project. Baby step #1 is extracting the number ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
electic
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
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
lanycrost
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

Other popular topics Top

srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
albydarned
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
sergio_101
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
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
romenigld
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

We're in Beta

About us Mission Statement