akkoma/lib/pleroma/workers/publisher_worker.ex

36 lines
1.3 KiB
Elixir
Raw Normal View History

# Pleroma: A lightweight social networking server
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Workers.PublisherWorker do
alias Pleroma.Activity
alias Pleroma.Web.Federator
use Pleroma.Workers.WorkerHelper, queue: "federator_outgoing"
2020-06-23 06:09:01 -06:00
def backoff(%Job{attempt: attempt}) when is_integer(attempt) do
Pleroma.Workers.WorkerHelper.sidekiq_backoff(attempt, 5)
end
@impl Oban.Worker
def perform(%Job{args: %{"op" => "publish", "activity_id" => activity_id, "object_data" => nil}}) do
activity = Activity.get_by_id(activity_id)
2022-12-12 11:55:28 -07:00
IO.inspect(activity)
Federator.perform(:publish, activity)
end
@impl Oban.Worker
def perform(%Job{
args: %{"op" => "publish", "activity_id" => activity_id, "object_data" => object_data}
}) do
activity = Activity.get_by_id(activity_id)
activity = %{activity | data: Map.put(activity.data, "object", Jason.decode!(object_data))}
Federator.perform(:publish, activity)
end
2020-06-23 06:09:01 -06:00
def perform(%Job{args: %{"op" => "publish_one", "module" => module_name, "params" => params}}) do
params = Map.new(params, fn {k, v} -> {String.to_atom(k), v} end)
Federator.perform(:publish_one, String.to_atom(module_name), params)
end
end