We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
Starting child processes depending on the environment
almirsarajcic
Created
Sometimes, you don’t want to run every part of your Elixir application in all Mix environments.
For example, you might want to skip some background jobs when running in the test environment.
To accomplish that, you can conditionally start child processes in your application.
def start(_type, _args) do
children =
[
# ...
] ++ more_children()
# ...
end
defp more_children(env \\ Application.get_env(:my_app, :env))
defp more_children(:test), do: []
defp more_children(_env) do
[
MyApp.Scheduler
]
end
Note: you can’t use Mix.env()
here because Mix is unavailable in Elixir releases.
Check out https://elixirdrops.net/d/2KpcFEAG
Copy link
copied to clipboard