X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fweb%2Ffederator%2Fretry_queue.ex;h=3db948c2edf7540b09d61ccfd1c3b03bd716a416;hb=f4447d82b814e4710a0d7499bc0707773ac1e440;hp=e4340af7c10118447c9a9182c90764375f394a20;hpb=cb286fdeba1782b75d1d7bca484d80e3cd499a98;p=akkoma
diff --git a/lib/pleroma/web/federator/retry_queue.ex b/lib/pleroma/web/federator/retry_queue.ex
index e4340af7c..3db948c2e 100644
--- a/lib/pleroma/web/federator/retry_queue.ex
+++ b/lib/pleroma/web/federator/retry_queue.ex
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Federator.RetryQueue do
@@ -7,21 +7,17 @@ defmodule Pleroma.Web.Federator.RetryQueue do
require Logger
- # seconds
- @initial_timeout 30
- @max_retries 5
-
- @max_jobs 20
-
def init(args) do
queue_table = :ets.new(:pleroma_retry_queue, [:bag, :protected])
{:ok, %{args | queue_table: queue_table, running_jobs: :sets.new()}}
end
- def start_link() do
+ def start_link do
enabled =
- if Mix.env() == :test, do: true, else: Pleroma.Config.get([:retry_queue, :enabled], false)
+ if Pleroma.Config.get(:env) == :test,
+ do: true,
+ else: Pleroma.Config.get([__MODULE__, :enabled], false)
if enabled do
Logger.info("Starting retry queue")
@@ -45,23 +41,23 @@ defmodule Pleroma.Web.Federator.RetryQueue do
GenServer.cast(__MODULE__, {:maybe_enqueue, data, transport, retries + 1})
end
- def get_stats() do
+ def get_stats do
GenServer.call(__MODULE__, :get_stats)
end
- def reset_stats() do
+ def reset_stats do
GenServer.call(__MODULE__, :reset_stats)
end
def get_retry_params(retries) do
- if retries > @max_retries do
+ if retries > Pleroma.Config.get([__MODULE__, :max_retries]) do
{:drop, "Max retries reached"}
else
{:retry, growth_function(retries)}
end
end
- def get_retry_timer_interval() do
+ def get_retry_timer_interval do
Pleroma.Config.get([:retry_queue, :interval], 1000)
end
@@ -93,9 +89,8 @@ defmodule Pleroma.Web.Federator.RetryQueue do
)
popped
- |> List.foldl(true, fn e, acc ->
+ |> Enum.each(fn e ->
:ets.delete_object(table, e)
- acc
end)
popped
@@ -108,12 +103,12 @@ defmodule Pleroma.Web.Federator.RetryQueue do
current_time = DateTime.to_unix(DateTime.utc_now())
n_running_jobs = :sets.size(running_jobs)
- if n_running_jobs < @max_jobs do
+ if n_running_jobs < Pleroma.Config.get([__MODULE__, :max_jobs]) do
n_ready_jobs = ets_count_expires(queue_table, current_time)
if n_ready_jobs > 0 do
# figure out how many we could start
- available_job_slots = @max_jobs - n_running_jobs
+ available_job_slots = Pleroma.Config.get([__MODULE__, :max_jobs]) - n_running_jobs
start_n_jobs(running_jobs, queue_table, current_time, available_job_slots)
else
running_jobs
@@ -226,18 +221,19 @@ defmodule Pleroma.Web.Federator.RetryQueue do
{:noreply, state}
end
- if Mix.env() == :test do
+ if Pleroma.Config.get(:env) == :test do
defp growth_function(_retries) do
- _shutit = @initial_timeout
+ _shutit = Pleroma.Config.get([__MODULE__, :initial_timeout])
DateTime.to_unix(DateTime.utc_now()) - 1
end
else
defp growth_function(retries) do
- round(@initial_timeout * :math.pow(retries, 3)) + DateTime.to_unix(DateTime.utc_now())
+ round(Pleroma.Config.get([__MODULE__, :initial_timeout]) * :math.pow(retries, 3)) +
+ DateTime.to_unix(DateTime.utc_now())
end
end
- defp maybe_kickoff_timer() do
+ defp maybe_kickoff_timer do
GenServer.cast(__MODULE__, :kickoff_timer)
end
end