juanseph

juanseph

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 = [
      Alerts.Repo,
      supervisor(:odbc, []),
      supervisor(AlertsWeb.Endpoint, []),
      if(System.get_env() != :test, do: Alerts.Scheduler)
    ]

    # See https://hexdocs.pm/elixir/Supervisor.html
    # for other strategies and supported options
    opts = [strategy: :one_for_one, name: Alerts.Supervisor]
    Supervisor.start_link(children, opts)
  end

What kind of children specification should I provide?

Thanks

Most Liked

NobbZ

NobbZ

: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.

dimitarvp

dimitarvp

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

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

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

Where Next?

Popular in Questions Top

stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New

Other popular topics Top

ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 49266 226
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New

We're in Beta

About us Mission Statement