And you will see that you get the error you expect. That implies that you are not hitting the branch of the case statement that you expect. So I’d do this to being with:
case Application.compile_env(:kcore, :app_env) |> IO.inspect()
Okay nice, now remember that module attributes are set at compile time, you have said you set the config in rumtime.exs. What happens if you move that into config/dev.exs ?
I want to understand Which config file to use and when?
Great question. In general what you have here is a bit of an anti-pattern which I’ll explain a bit. But first in general you put the config inside runtime.exs ONLY if you will only know the value at runtime. When might this be the case? Some examples are:
You build your app on a build server, then move the executable to a different server to run it. The server that you run the app on has the env vars and secrets on it. In that case any env var is only going to be available at runtime, so you’d have to set them in runtime.exs.
You want to be able to re-start the app to change config values, rather than have to rebuild a release.
In most other cases you can likely set it at compile time. Now this though is a bit of a smell:
so wee use runtime.exs , for putting env values to app , afterthe build has been built. and we are running that binary on d/f machines , without need of compiling for each d/f machines with d/f config?
A bit off-topic, but you do know that when you use a module variable it is set at compile time, that means in this case that the DateTime.utc_now() is the value at compile time.
Just wondering.
yea it’s true I didn’t even get to that, it’s hard to tell from the example but it’s more likely you just want to store the :hour, :day offset atom in the config as that’s the thing that changes really