Starting the mixing process

New to Elixir, but still loved :)

Many of my mixing tasks depend on HTTPotion.

My mix.exs file is declared as such

  def application do [ applications: [:logger, :cowboy, :plug, :httpotion, :poison], mod: {BiddingAgent, []} ] end 

Thus, HTTPotion.start is called automatically. However, when I run a task like mix campaign.list , which should trigger an HTTP request, I need to manually call HTTPotion.start .

What is the idiomatic way to make sure the right processes are running for my mix tasks?

Thanks!

+6
source share
1 answer

You are correct, when you start the application outside of the script run, you need to manually run the dependencies.

I prefer to call the Application module directly instead of each dependency.

Add the following code to the run function inside your task module.

 {:ok, _started} = Application.ensure_all_started(:httpotion) 

If you have any doubts, you can take a look at the documentation

Edit: The practice described is used in Ecto

The module is included in the mix tasks, which the sure_started method provides.

+10
source

All Articles