Migration from poolboy
View Source
If you are using :poolboy and want to use Poolex instead, then you need to follow three simple steps.
Installation steps
I. Install the Poolex dependency
mix.exs
defp deps do
[
- {:poolboy, "~> 1.5.0"}
+ {:poolex, "~> 1.0"}
]
endInstall it.
mix deps.get
Well, you can also clean up installed dependencies locally and remove them from the lock file.
mix deps.clean --unlock --unused
II. Update child specs
Your Application or Supervisor file
def init(_args) do
children = [
- :poolboy.child_spec(:some_pool,
- name: {:local, :some_pool},
- worker_module: MyApp.SomeWorker,
- size: 100,
- max_overflow: 50
- )
+ {Poolex,
+ pool_id: {:local, :some_pool},
+ worker_module: MyApp.SomeWorker,
+ workers_count: 100,
+ max_overflow: 50}
]
Supervisor.init(children, strategy: :one_for_one)
endIII. Update call site
Use run/3.
Be careful, unlike :poolboy.transaction, Poolex.run returns {:ok, result}.
- result = :poolboy.transaction(
- :some_pool,
- fn pid -> some_function(pid) end,
- :timer.seconds(10)
- )
+ {:ok, result} = Poolex.run(
+ :some_pool,
+ fn pid -> some_function(pid) end,
+ checkout_timeout: :timer.seconds(10)
+ )