mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-12-24 18:15:19 +00:00
federator: publisher: integrate job queue, simplify publish_one logic
This commit is contained in:
parent
ef1f9e8d4e
commit
0afc8d7856
|
@ -3,6 +3,10 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.Federator.Publisher do
|
||||
alias Pleroma.Web.Federator.RetryQueue
|
||||
|
||||
require Logger
|
||||
|
||||
@moduledoc """
|
||||
Defines the contract used by federation implementations to publish messages to
|
||||
their peers.
|
||||
|
@ -24,15 +28,26 @@ defmodule Pleroma.Web.Federator.Publisher do
|
|||
"""
|
||||
@callback publish(Pleroma.User.t(), Pleroma.Activity.t()) :: :ok | {:error, any()}
|
||||
|
||||
@doc """
|
||||
Enqueues work generated by the federation module.
|
||||
"""
|
||||
@spec enqueue(module(), keyword()) :: :ok
|
||||
def enqueue(module, args), do: PleromaJobQueue.enqueue(:federation_outgoing, module, args)
|
||||
|
||||
@doc """
|
||||
Enqueue publishing a single activity.
|
||||
"""
|
||||
@spec enqueue_one(module(), Map.t()) :: :ok
|
||||
def enqueue_one(module, %{} = args), do: enqueue(module, [:publish_one, args])
|
||||
def enqueue_one(module, %{} = params),
|
||||
do: PleromaJobQueue.enqueue(:federation_outgoing, __MODULE__, [:publish_one, module, params])
|
||||
|
||||
@spec perform(atom(), module(), any()) :: {:ok, any()} | {:error, any()}
|
||||
def perform(:publish_one, module, params) do
|
||||
case apply(module, :publish_one, [params]) do
|
||||
{:ok, _} ->
|
||||
:ok
|
||||
|
||||
{:error, _} ->
|
||||
RetryQueue.enqueue(params, module)
|
||||
end
|
||||
end
|
||||
|
||||
def perform(type, _, _) do
|
||||
Logger.debug("Unknown task: #{type}")
|
||||
{:error, "Don't know what to do with this"}
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue