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.)

IloSophiep

IloSophiep

If you are in control of when the configuration changes, you could add an endpoint that “accepts and applies” config values you send in via HTTP?

No need for UI and all that work to get started. Just plain JSON (or whatever) in and you are good to go?

Nicd

Nicd

You can use Application.put_env to change configuration at runtime.

Where Next?

Popular in Questions Top

jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
logicmason
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
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
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
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
New
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
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

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3268 119930 1237
New
peerreynders
Manning 2016 Halloween weekend sale via Deal of the Day Friday, October 28 - Half off all MEAPs - code WM102816LT Saturday, October 29 ...
326 29600 154
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
977 41022 311
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
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
quazar
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
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 42633 214
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
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New

We're in Beta

About us Mission Statement