Merge branch 'issue/2069' into 'develop'
[akkoma] / lib / pleroma / web / fed_sockets / ingester_worker.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.FedSockets.IngesterWorker do
6 use Pleroma.Workers.WorkerHelper, queue: "ingestion_queue"
7 require Logger
8
9 alias Pleroma.Web.Federator
10
11 @impl Oban.Worker
12 def perform(%Job{args: %{"op" => "ingest", "object" => ingestee}}) do
13 try do
14 ingestee
15 |> Jason.decode!()
16 |> do_ingestion()
17 rescue
18 e ->
19 Logger.error("IngesterWorker error - #{inspect(e)}")
20 e
21 end
22 end
23
24 defp do_ingestion(params) do
25 case Federator.incoming_ap_doc(params) do
26 {:error, reason} ->
27 {:error, reason}
28
29 {:ok, object} ->
30 {:ok, object}
31 end
32 end
33 end