[#1149] Addressed code review comments (code style, jobs pruning etc.).
[akkoma] / lib / pleroma / workers / worker_helper.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Workers.WorkerHelper do
6 alias Pleroma.Config
7
8 def worker_args(queue) do
9 case Config.get([:workers, :retries, queue]) do
10 nil -> []
11 max_attempts -> [max_attempts: max_attempts]
12 end
13 end
14
15 def sidekiq_backoff(attempt, pow \\ 4, base_backoff \\ 15) do
16 backoff =
17 :math.pow(attempt, pow) +
18 base_backoff +
19 :rand.uniform(2 * base_backoff) * attempt
20
21 trunc(backoff)
22 end
23 end