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?
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #elixirconf-eu
- #metaprogramming
- #hex











Showing Posts 1 to 5- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
KallDrexx
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 myX.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 justApplication.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
Hi,
Well It depends on the generation time of the config.
config.exsof the final application usingconfig :x, key: value[to set] andApplication.get_env(:x, :key)[to fetch]. See also the remark at the andif the config state is only known at startup time you could use [EDIT: See following replyApplication.start/2] (http://elixir-lang.org/docs/stable/elixir/Application.html#module-application-module-callback) and start the application usingSupervisor.Xwith startup time config then creating anAgentis the way to goSee also this question for a related problem I had a while ago, regarding the non-usability of
config.exsfrom dependent packages.KallDrexx
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
You are right. this is wrong:
In fact it might be better to rely on
Application.get_env/put_envalone 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:
X.start/2X.start/2starts the supervisor viaSupervisor.start_link/2(Proc 2)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.exsmod:{X,args}are better suited thanconfig :app, argsinconfig.exs. Perhaps someone else finds one?marciol
I was wondering the same question when finally I remembered that
ExUnithas 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