How to determine if app is launched standalone vs in umbrella?

I’m building an umbrella app where at least some of the apps are Phoenix apps. Most of the time (including in production), I launch the “main” app and have it forward requests to the appropriate child. Sometimes, though, I want to test just this application.

So that means I need the child app’s endpoint to be launched, but only when launching standalone. Right now I’m doing that by sniffing the output of System.get_cwd/0 like this:

was_launched_standalone? = System.cwd |> Path.basename |> String.equivalent?("user")

but that feels hacky. Is there a more appropriate way to ask this question?

1 Like

Mix detects wether the current task is executed in umbrella child this way:

So it looks like they check if grandparent path is umbrella project and current project root is a child app.

If you know the other apps you could also determine if the other app is loaded/started with:

iex(1)> Application.loaded_applications
[{:compiler, 'ERTS  CXC 138 10', '7.0'}, {:logger, 'logger', '1.3.3'},
 {:stdlib, 'ERTS  CXC 138 10', '3.0'}, {:kernel, 'ERTS  CXC 138 10', '5.0'},
 {:elixir, 'elixir', '1.3.3'}, {:iex, 'iex', '1.3.3'}]
iex(2)> Application.started_applications
[{:logger, 'logger', '1.3.3'}, {:iex, 'iex', '1.3.3'},
 {:elixir, 'elixir', '1.3.3'}, {:compiler, 'ERTS  CXC 138 10', '7.0'},
 {:stdlib, 'ERTS  CXC 138 10', '3.0'}, {:kernel, 'ERTS  CXC 138 10', '5.0'}]

OK, thanks. I’ve since redesigned in such a way as to avoid this question altogether, but this looks helpful.