Add option to modify HTTP pool size
[akkoma] / lib / pleroma / workers / publisher_worker.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Workers.PublisherWorker do
6 alias Pleroma.Activity
7 alias Pleroma.Web.Federator
8
9 use Pleroma.Workers.WorkerHelper, queue: "federator_outgoing"
10
11 def backoff(%Job{attempt: attempt}) when is_integer(attempt) do
12 Pleroma.Workers.WorkerHelper.sidekiq_backoff(attempt, 5)
13 end
14
15 @impl Oban.Worker
16 def perform(%Job{args: %{"op" => "publish", "activity_id" => activity_id, "object_data" => nil}}) do
17 activity = Activity.get_by_id(activity_id)
18 Federator.perform(:publish, activity)
19 end
20
21 @impl Oban.Worker
22 def perform(%Job{
23 args: %{"op" => "publish", "activity_id" => activity_id, "object_data" => object_data}
24 }) do
25 activity = Activity.get_by_id(activity_id)
26 activity = %{activity | data: Map.put(activity.data, "object", Jason.decode!(object_data))}
27 Federator.perform(:publish, activity)
28 end
29
30 def perform(%Job{args: %{"op" => "publish_one", "module" => module_name, "params" => params}}) do
31 params = Map.new(params, fn {k, v} -> {String.to_atom(k), v} end)
32 Federator.perform(:publish_one, String.to_atom(module_name), params)
33 end
34 end