anuaralfetahe

anuaralfetahe

Does elixir actualy compile the .exs files?

Recently I found out that changes made to the config.exs file did not apply to the running app.
I had to recompile and restart the app with iex -S mix.
I always thought that .exs files were not being compiled and interpreted when used.
Why keep configurations in the .exs file and not in the .ex if both are compiled?

I have read about runtime and compile time configurations and System.get_env/2 seems to be the only option for updating the configurations without actualy recompiling the app. If I am keeping my configurations in plain elixir in the runtime.exs file do I always need to recompile when making conf changes?

I would be very happy to hear how other people manage their application configurations. Thanks :slight_smile:

Marked As Solved

derek-zhou

derek-zhou

I’d make a companion command-line tool that send/update the config in the server, through a UNIX domain socket. You can use a HTTP API as @IloSophiep suggested but then you’d need to worry about securing the HTTP endpoint with auth.

Also Liked

derek-zhou

derek-zhou

Elixir is a compiled language. The only difference between .ex and .exs is the .ex file is compiled and written out as a binary file on the disk, but the .exs is compiled on the fly into memory and not serialized out.

The typical usage of runtime.exs is to read values from environment variables then config the application at runtime. So you don’t change runtime.exs, only the startup script that set those environment variables.

In most web applications, the majority of the configurations are admin changeable from the UI, and those are typically backed by the database. The amount of flat file configuration is kept low. We don;t want to restart the application too often, right?

stefanchrobot

stefanchrobot

config/config.exs is read during build time and config/runtime.exs is read during application startup. Both of them are evaluated only once. To change the config of your app while it’s running, you need to do a bit of work yourself. I don’t think Elixir provides any tools for that out of the box.

Qqwy

Qqwy

TypeCheck Core Team

Be aware however, that there are quite a number of tools which only look at the configuration when they themselves first start up (which is usually at elixir-application-startup time), after which changing the configuration settings using e.g. Application.put_env might have little effect.
Check the particular tool(s) you are using to be sure if/when it reads the configuration.

(And generally speaking it is nice if tools are able to pick up new configuration at runtime, because it is not rare to want to alter how something behaves at runtime at all.)

Where Next?

Popular in Questions Top

siddhant3030
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
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
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
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
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New

Other popular topics Top

stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
RisingFromAshes
I've read in another post that it may be possible with a router helper - but I couldn't find an appropriate one, and tbh, I'm still just ...
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
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

We're in Beta

About us Mission Statement