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
: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
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]
1
Popular in Questions
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
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
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
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
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
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
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
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
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
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...
New
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
After calling mix ecto.create I get this error:
17:00:32.162 [error] GenServer #PID<0.412.0> terminating
** (Postgrex.Error) FATAL...
New
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
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









