Search code examples
elixirphoenix-frameworkelixir-mix

How to detect phoenix application started from `mix phx.server`?


I have some workers (children) in Application.start. They shouldn't be started if phoenix app running from task other than mix phx.server (for example with mix ecto.reset).
So, how to know in Application.start that it is mix phx.server running the code?


Solution

  • You can use Phoenix.Endpoint.server?(otp_app, endpoint) to check if an endpoint is running its server under the given app. Here are the docs: https://hexdocs.pm/phoenix/Phoenix.Endpoint.html#server?/2