You’re right, I definitely haven’t internalised Elixir is expression based. I’m barely 4 days in. I’m sure I’ll get there.
Thanks for the explanation, I’ll keep reading/learning.
I would be interested to see an example of how I would express those two states of children. Perhaps using children = case unquote(Mix.env()) do... as above?
children = if System.get_env("APP_WORKER") do
[
supervisor(Verk.Supervisor, [])
]
else
[
supervisor(Pink.Repo, []),
supervisor(PinkWeb.Endpoint, []),
worker(Redix,
[Confex.get_env(:verk, :redis_url), [name: Verk.Redis]], id: Verk.Redis
)
]
end
Conceptually from the code you’ve shown your intent seems to be
{children, redis_url} = if app_worker?() do
...
{app_worker_children, nil} # i.e. is it actually nil or is it already a some default value?
else
...
{other_children, other_redis_url}
end
Maybe. But I don’t need two return values, and I don’t need access to redis_url outside of the expression. That was mainly just a helper to clean up the worker definition pulled from Verk codebase. Though I reckon moving that, along with the APP_WORKER ENV variable fetch into their own functions would be cleaner.
Appreciate the suggestions. This is my first foray into a functional language.
Just a note: mix run would only work if mix is available.
So on a “production” machine (with or without docker) I would recommend using bitwalker/distillery.
It makes creating otp releases rather easy and possible to run them without any need for mix.