29 lines
960 B
Elixir
29 lines
960 B
Elixir
# Pleroma: A lightweight social networking server
|
|
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
defmodule Pleroma.Workers.PublisherWorker do
|
|
alias Pleroma.Activity
|
|
alias Pleroma.Web.Federator
|
|
|
|
# Note: `max_attempts` is intended to be overridden in `new/2` call
|
|
use Oban.Worker,
|
|
queue: "federator_outgoing",
|
|
max_attempts: 1
|
|
|
|
def backoff(attempt) when is_integer(attempt) do
|
|
Pleroma.Workers.WorkerHelper.sidekiq_backoff(attempt, 5)
|
|
end
|
|
|
|
@impl Oban.Worker
|
|
def perform(%{"op" => "publish", "activity_id" => activity_id}, _job) do
|
|
activity = Activity.get_by_id(activity_id)
|
|
Federator.perform(:publish, activity)
|
|
end
|
|
|
|
def perform(%{"op" => "publish_one", "module" => module_name, "params" => params}, _job) 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
|