logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git
commit: f74f5e0a56277507e7bc3df7251ec58b6c8b41cb
parent 8ac4458630026387a5394b427daa409b0d2667ba
Author: Haelwenn <contact+git.pleroma.social@hacktivis.me>
Date:   Fri, 29 Dec 2023 23:18:34 +0000

Merge branch 'publisher' into 'develop'

Discard some failed publisher jobs

See merge request pleroma/pleroma!4022

Diffstat:

Achangelog.d/publisher_discard.change1+
Achangelog.d/publisher_log.change1+
Mlib/pleroma/web/activity_pub/publisher.ex19++++++++++++++++---
Mtest/pleroma/web/activity_pub/publisher_test.exs3++-
4 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/changelog.d/publisher_discard.change b/changelog.d/publisher_discard.change @@ -0,0 +1 @@ +Activity publishing failures will prevent the job from retrying if the publishing request returns a 403 or 410 diff --git a/changelog.d/publisher_log.change b/changelog.d/publisher_log.change @@ -0,0 +1 @@ +Publisher errors will now emit logs indicating the inbox that was not available for delivery. diff --git a/lib/pleroma/web/activity_pub/publisher.ex b/lib/pleroma/web/activity_pub/publisher.ex @@ -117,10 +117,23 @@ defmodule Pleroma.Web.ActivityPub.Publisher do result else - {_post_result, response} = e -> + {_post_result, %{status: code} = response} = e -> unless params[:unreachable_since], do: Instances.set_unreachable(inbox) - Logger.error("Failed to publish activity #{id} #{inspect(e)}") - {:error, response} + Logger.metadata(activity: id, inbox: inbox, status: code) + Logger.error("Publisher failed to inbox #{inbox} with status #{code}") + + case response do + %{status: 403} -> {:discard, :forbidden} + %{status: 404} -> {:discard, :not_found} + %{status: 410} -> {:discard, :not_found} + _ -> {:error, e} + end + + e -> + unless params[:unreachable_since], do: Instances.set_unreachable(inbox) + Logger.metadata(activity: id, inbox: inbox) + Logger.error("Publisher failed to inbox #{inbox} #{inspect(e)}") + {:error, e} end end diff --git a/test/pleroma/web/activity_pub/publisher_test.exs b/test/pleroma/web/activity_pub/publisher_test.exs @@ -212,7 +212,8 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do actor = insert(:user) inbox = "http://404.site/users/nick1/inbox" - assert {:error, _} = Publisher.publish_one(%{inbox: inbox, json: "{}", actor: actor, id: 1}) + assert {:discard, _} = + Publisher.publish_one(%{inbox: inbox, json: "{}", actor: actor, id: 1}) assert called(Instances.set_unreachable(inbox)) end