appcues / mojito

An easy-to-use Elixir HTTP client, built on the low-level Mint library.
https://hexdocs.pm/mojito/Mojito.html
MIT License
349 stars 34 forks source link

task mode: unknown registry: Mojito.Pool.Poolboy.Registry #49

Closed densin27 closed 4 years ago

densin27 commented 4 years ago

just simple code Mojito.request(method: :get, url: "http://127.0.0.1" ) work fine in "mix run".

but when use in Mix.Task , it got error. Compiling 1 file (.ex) ** (ArgumentError) unknown registry: Mojito.Pool.Poolboy.Registry (elixir) lib/registry.ex:1243: Registry.key_info!/1 (elixir) lib/registry.ex:568: Registry.lookup/2 lib/mojito/pool/poolboy.ex:65: Mojito.Pool.Poolboy.get_pools/1 lib/mojito/pool/poolboy.ex:49: Mojito.Pool.Poolboy.get_pool/1 lib/mojito/pool/poolboy.ex:28: Mojito.Pool.Poolboy.request/1 lib/httpc.ex:4: Httpc.get/1 lib/task/test.ex:26: Mix.Tasks.Web.geturl/1 (mix) lib/mix/task.ex:331: Mix.Task.run_task/3 (mix) lib/mix/cli.ex:79: Mix.CLI.run_task/2 (elixir) lib/code.ex:813: Code.require_file/2

Mojito's problem ? or poolboy's ?

densin27 commented 4 years ago

and I already also try to Application.ensure_all_started for :poolboy in task script.

[:postgrex, :ecto, :timex, :poolboy] |> Enum.each(&Application.ensure_all_started/1)

still got same error.

gamache commented 4 years ago

Thanks for this report -- I will look into it in the next couple of days.

m0rt3nlund commented 4 years ago

Have you also tried to start the :mojito application? Had the same problem and this was what I was missing in my mix.exs file :)

kitplummer commented 4 years ago

Run into this, with Mojito in a library that provides a Mix.Tasks implementation. Elixir noob, so I'm not even sure if it is possible - can't impose an application into a library right?

gamache commented 4 years ago

This is a problem common to Mix tasks; it affects any applications that need to start other applications or set up infrastructure in order to function properly. The solution here is to manually add Application.ensure_all_started(:mojito) at the beginning of the task.