Starting supervised odbc at Phoenix application startup

Hi, I am doing a phoenix app that uses erlang odbc

I want to boot the erlang odbc application (:odbc.start()) when starting the phoenix app. My understanding is that the way to do it is to add it to the supervised children

Something like the following

  def start(_type, _args) do
    import Supervisor.Spec

    # Define workers and child supervisors to be supervised
    children = [
      supervisor(:odbc, []),
      supervisor(AlertsWeb.Endpoint, []),
      if(System.get_env() != :test, do: Alerts.Scheduler)

    # See
    # for other strategies and supported options
    opts = [strategy: :one_for_one, name: Alerts.Supervisor]
    Supervisor.start_link(children, opts)

What kind of children specification should I provide?


:odbc is already a supervised application contained in the Erlang standard distribution, just add it to your mix.exs as :extra_applications.

There is no need to add it to your supervision tree.

1 Like

As a general code readability advice, change your code to this:

    children =
        supervisor(:odbc, []),
        supervisor(AlertsWeb.Endpoint, [])
      ++ extra_children(System.get_env())

def extra_children(:test), do: []
def extra_children(_), do: [Alerts.Scheduler]
1 Like