- @spec get_conn(URI.t(), keyword()) :: {:ok, keyword()} | {:error, atom()}
- def get_conn(uri, opts) do
- case ConnectionPool.get_conn(uri, opts) do
- {:ok, conn_pid} -> {:ok, Keyword.merge(opts, conn: conn_pid, close_conn: false)}
- err -> err
- end
+ @prefix Pleroma.Gun.ConnectionPool
+ def limiter_setup do
+ wait = Config.get([:connections_pool, :connection_acquisition_wait])
+ retries = Config.get([:connections_pool, :connection_acquisition_retries])
+
+ :pools
+ |> Config.get([])
+ |> Enum.each(fn {name, opts} ->
+ max_running = Keyword.get(opts, :size, 50)
+ max_waiting = Keyword.get(opts, :max_waiting, 10)
+
+ result =
+ ConcurrentLimiter.new(:"#{@prefix}.#{name}", max_running, max_waiting,
+ wait: wait,
+ max_retries: retries
+ )
+
+ case result do
+ :ok -> :ok
+ {:error, :existing} -> :ok
+ end
+ end)
+
+ :ok