vrod
Forgive me for maybe a noob question. I am reading much about configuration – maybe this in Elixir is one of the most confusing things? I read this Configuring your Elixir Application at Runtime with Vapor | AppSignal Blog and it says “if it can be set at runtime, it should be set at runtime.” This makes much sense to me – this is how other languages work with .env files – but maybe the comparison is not fair with dynamic languages?
My question is what things can not be runtime config? I imagine a very simple setup from working with PHP where there was only 1 config and 2 .env files (regular .env and a .test.env) and the test suite would know to use the .test.env. But dynamic languages do not have the same concerns. I am thinking maybe a config for a module name like saying which HTTP client the app should use. A system ENV maybe has string for “HTTPoison”, but you must convert this to atom like Elixir.HTTPoison. It is ugly, but I think this works fine. What things will not work this way and must be set in a config file for compile time config?
Thank you for your replies!
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
- #elixir-ls
- #blog-post
- #ai
- #phoenix_html
- #elixirconf-us
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Marked As Solved- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
Nicd
This suffers from being long and containing
ifs, but I’m posting it anyway for reference. I went 100% onruntime.exsin my project and only have a couple of things that need to be set at compile time in theconfig.exs..envwhen developing locallyThis has worked well for me. Even though the runtime config file is big, it’s not really that big once you get to know it, and I can have unified config for both development and release time (just using
.envin development for convenience).Also Liked
hauleth
There are basic 2 types of config in Elixir code:
Application.get_env/{2,3}in any part of the code, even compile time, so people often did stuff like: This caused the@optionto be set during compilation, so if someone was using releases (Distillery or Relx at the time) could be confused why@optiondidn’t changed when the configuration was changed on the target server. Since 1.10 we haveApplication.compile_env/{2,3}andApplication.get_env/{2,3}will print warning when used in compile time. There are few examples of applications that use compile time env and in few situations this still sometimes makes some sense (for example poor-man dependency injection).Application.get_env/{2,3}calls within functions body, that is it. The “funny” thing there is that runtime configuration is also divided in 2 separate things (and people often forgot about it):Applicationbehaviour, or ininit/1functions of the servers). This is for example reason why simpleApplication.put_env(:logger, :level, :warning)will not work, and you need to useLogger.configure(level: :warning)or reason why you cannot configure:kerneland:stdlibapplications viaconfig/config.exs(so for example configuration of Erlang’sloggeris currently enormous PITA in Elixir).Application.get_env/{2,3}is called “in-place”, where it is needed. Reason why a lot components cannot be configured that way are mainly 2:So
1.is obviously something that you cannot configure in runtime (examples of such behaviour is:mimedatabase). And depending when yourVaporconfiguration will be ran1.1.can also be off limits, at least for some applications (notably:kerneland:stdlibare hard to configure with any Elixir tooling).dch
The
Application.envis 100% ets:You can look in the observer app, if you select
view -> ETS tables -> system tablestoo.For better (read-only) performance, look at persistent_term — OTP 29.0.2 (erts 17.0.2) the persistent term cache, added in OTP21.2. Note that updating this is a java-esque stop-the-world scenario for the entire VM.
lud
The first thing I can think off are modules names that macros will be used from, or will be modules generated by macros.
Basically, anything that changes the compilation result.