vegabook

vegabook

How to specifiy location of DETS table files for a library

I’m writing a Bloomberg terminal API library for Elixir, and this library will need to store some mutable startup configuration in a DETS table. Specifically, ticker streams that are subscribed to during a session can (optionally) be stored, reloaded the next time a session is started, and resubscribed-to.

So now I need a file location for the DETS table. I could force one on users for example ~/.lib_name/application_name_subs.dets, but it seems right to be able to allow users to override such a location.

Problem is the library guidelines says one should avoid application-level configuration.

But in the case I mention, I’m going to guess application level configuration for such an override option is okay? What are the alternatives for the above?

First 4 of 4 Posts Switch mode

al2o3cr

al2o3cr

Where in the code is a session “started”? That’s where I’d start looking for a place to supply config.

For instance, here’s how Oban does it (from the installation guide):

# config/config.exs
config :my_app, Oban,
  repo: MyApp.Repo,
  plugins: [Oban.Plugins.Pruner],
  queues: [default: 10]

# lib/my_app/application.ex
def start(_type, _args) do
  children = [
    MyApp.Repo,
    {Oban, Application.fetch_env!(:my_app, Oban)}
  ]

  Supervisor.start_link(children, strategy: :one_for_one, name: MyApp.Supervisor)
end
vegabook

vegabook OP

Yeah so basically Oban is using global application configuration file?

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

Nope, see how it’s scoped under your app? And even that is a convention, you can just supply config directly to the child and skip the app env entirely.

al2o3cr

al2o3cr

The difference is small but important:

# avoid this
config :somebody_elses_library, foo: "bar"

# and in the supervisor
SomebodyElsesLibrary

(or not mentioned in the application supervisor at all and started via `extra_applications` etc)

--------------------------

# do this
config :my_app, SomebodyElsesLibrary, foo: "bar"

# and in the supervisor
{SomebodyElsesLibrary, Application.fetch_env!(:my_app, SomebodyElsesLibrary)}

A good way to check if you’re on the right path is to ask “can there be two of them?”

  • in the “don’t” case, there’s nowhere for that second config to go. Back when umbrella apps had separate config directories per-app, people would try to configure the same app differently in different child apps only to discover that all the app configs were always loaded

  • in the “do” case, all it takes is more of the same:

config :my_app, SomebodyElsesLibrary, foo: "bar"
config :my_app, SomebodyElsesLibraryWithBellsOn, foo: "bar with bells on", name: WithBellsOn

# and in the supervisor
{SomebodyElsesLibrary, Application.fetch_env!(:my_app, SomebodyElsesLibrary)},
{SomebodyElsesLibrary, Application.fetch_env!(:my_app, SomebodyElsesLibraryWithBellsOn)},
— All posts loaded —

Where Next?

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
silverdr
Using Phoenix.LiveView.TagEngine as an EEx.Engine is deprecated! To compile HEEx, use Phoenix.LiveView.TagEngine.compile/2 instead. Sta...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
michallepicki
I am using Oban and occasionally, shortly after a deployment, a handful of jobs can fail because of dependency on other parts of the syst...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New

We're in Beta

About us Mission Statement