defmodule Pleroma.Gun.ConnectionPool.Reclaimer do
use GenServer, restart: :temporary
- @registry Pleroma.Gun.ConnectionPool
+ defp registry, do: Pleroma.Gun.ConnectionPool
def start_monitor do
pid =
- case :gen_server.start(__MODULE__, [], name: {:via, Registry, {@registry, "reclaimer"}}) do
+ case :gen_server.start(__MODULE__, [], name: {:via, Registry, {registry(), "reclaimer"}}) do
{:ok, pid} ->
pid
# {worker_pid, crf, last_reference} end)
unused_conns =
Registry.select(
- @registry,
+ registry(),
[
{{:_, :"$1", {:_, :"$2", :"$3", :"$4"}}, [{:==, :"$2", []}], [{{:"$1", :"$3", :"$4"}}]}
]
alias Pleroma.Gun
use GenServer, restart: :temporary
- @registry Pleroma.Gun.ConnectionPool
+ defp registry, do: Pleroma.Gun.ConnectionPool
def start_link([key | _] = opts) do
- GenServer.start_link(__MODULE__, opts, name: {:via, Registry, {@registry, key}})
+ GenServer.start_link(__MODULE__, opts, name: {:via, Registry, {registry(), key}})
end
@impl true
time = :erlang.monotonic_time(:millisecond)
{_, _} =
- Registry.update_value(@registry, key, fn _ ->
+ Registry.update_value(registry(), key, fn _ ->
{conn_pid, [client_pid], 1, time}
end)
time = :erlang.monotonic_time(:millisecond)
{{conn_pid, used_by, _, _}, _} =
- Registry.update_value(@registry, key, fn {conn_pid, used_by, crf, last_reference} ->
+ Registry.update_value(registry(), key, fn {conn_pid, used_by, crf, last_reference} ->
{conn_pid, [client_pid | used_by], crf(time - last_reference, crf), time}
end)
@impl true
def handle_call(:remove_client, {client_pid, _}, %{key: key} = state) do
{{_conn_pid, used_by, _crf, _last_reference}, _} =
- Registry.update_value(@registry, key, fn {conn_pid, used_by, crf, last_reference} ->
+ Registry.update_value(registry(), key, fn {conn_pid, used_by, crf, last_reference} ->
{conn_pid, List.delete(used_by, client_pid), crf, last_reference}
end)
Config.get([:pools, pool, :recv_timeout], default)
end
- @prefix Pleroma.Gun.ConnectionPool
def limiter_setup do
+ prefix = Pleroma.Gun.ConnectionPool
wait = Config.get([:connections_pool, :connection_acquisition_wait])
retries = Config.get([:connections_pool, :connection_acquisition_retries])
max_waiting = Keyword.get(opts, :max_waiting, 10)
result =
- ConcurrentLimiter.new(:"#{@prefix}.#{name}", max_running, max_waiting,
+ ConcurrentLimiter.new(:"#{prefix}.#{name}", max_running, max_waiting,
wait: wait,
max_retries: retries
)