KallDrexx

KallDrexx

I have a library application X that is setup to take in arguments via its start() function, and right now I’m successfully having these set via the mod keyword in mix.exs.

I am now writing another application (Y) that is using application X but it needs the ability to customize the arguments that it starts application X with (including renaming arguments Y has into what X expects.

I can’t find any documentation on how I can have application Y start application X with specific arguments. Applications.start() does not seem to take in arguments.

The only idea I have is having my start function in Y explicitly call X.start(type, args) and add that supervisor as a child to Y’s supervision tree.

Is that the correct way to go or am I missing something more obvious?

Showing Posts 1 to 5

KallDrexx

KallDrexx OP

After playing around a bit and reading whatever docs I could find (not much though), I did come up with a solution (though I’m not totally sure yet if it’s optimal).

Essentially instead of relying on the mod: keyword in mix.exs I am instead using environment variables in the mix.exs. In my X.start() function I will then turn the environment variables I am expecting into a keyword list I can then pass into the module expecting it.

I can then create a X.start_app() function that will take the values as function parameters and turn them into environment variables for application X (that way the exact variable names and whatnot are encapsulated within application X). After that I can just Application.ensure_all_started(:x) and theoretically that issue is solved.

I’m not sure if this is the most optimal solution but I think it solves my immediate need.

pba

pba

Hi,
Well It depends on the generation time of the config.

  • If you can define the config options at compile time , you can put them in config.exs of the final application using config :x, key: value[to set] and Application.get_env(:x, :key) [to fetch]. See also the remark at the and
  • if the config state is only known at startup time you could use [Application.start/2] (http://elixir-lang.org/docs/stable/elixir/Application.html#module-application-module-callback) and start the application using Supervisor. EDIT: See following reply
  • If You need runtime config, or multiple applications using X with startup time config then creating an Agent is the way to go

See also this question for a related problem I had a while ago, regarding the non-usability of config.exs from dependent packages.

KallDrexx

KallDrexx OP

This is the use case I am going to (one time initial startup) but your suggestion doesn’t work.

That doesn’t work because Application.start/2 doesn’t allow you to pass in arguments when starting an application (even though your implemented start function takes in arguments).

At the end of the day I realized I was designing this wrong and instead of making this an application it should instead just be a behavior that gets implemented anyway.

pba

pba

You are right. this is wrong:

In fact it might be better to rely on Application.get_env/put_env alone as the Application can be restarted At the Supervisors (dis)/grace.

As far as i understand it these are the processes in chronological start order:

  • Proc 1, the root supervisor calls X.start/2
  • X.start/2 starts the supervisor via Supervisor.start_link/2 (Proc 2)
  • The supervisor starts the dependency children (Procs 3-n)

Now Proc 2 should be able to restart Procs 3-n according to it’s strategy which is oblivious to the arguments within the Application domain.

EDIT: Indeed no use case is obvious to me, in which the arguments in mix.exs mod:{X,args} are better suited than config :app, args in config.exs. Perhaps someone else finds one?

marciol

marciol

I was wondering the same question when finally I remembered that ExUnit has and very elegant way to handle this same case.

https://github.com/elixir-lang/elixir/blob/b2b310e6b527f213b73e94f33aa5645c579792be/lib/ex_unit/lib/ex_unit.ex#L183-L218

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apz
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
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
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews