and i yoink (#275)

Co-authored-by: Mark Felder <feld@feld.me>
Co-authored-by: FloatingGhost <hannah@coffee-and-dreams.uk>
Reviewed-on: AkkomaGang/akkoma#275
This commit is contained in:
floatingghost 2022-11-14 15:07:26 +00:00
parent 893bfde66f
commit 2a1f17e3ed
7 changed files with 61 additions and 7 deletions

View file

@ -48,7 +48,9 @@ def publish(%{id: "pleroma:fakeid"} = activity) do
@impl true
def publish(%{data: %{"object" => object}} = activity) when is_binary(object) do
PublisherWorker.enqueue("publish", %{"activity_id" => activity.id, "object_data" => nil})
PublisherWorker.enqueue("publish", %{"activity_id" => activity.id, "object_data" => nil},
priority: publish_priority(activity)
)
end
@impl true
@ -63,7 +65,7 @@ def publish(%{data: %{"object" => object}} = activity) when is_map(object) or is
)
end
defp publish_priority(%{type: "Delete"}), do: 3
defp publish_priority(%{data: %{"type" => "Delete"}}), do: 3
defp publish_priority(_), do: 0
# Job Worker Callbacks

View file

@ -16,7 +16,7 @@ def process(backup, admin_user_id \\ nil) do
@impl Oban.Worker
def timeout(_job) do
Pleroma.Config.get([:workers, :timeout, :backup]) || :timer.minutes(1)
Pleroma.Config.get([:workers, :timeout, :backup], :timer.minutes(1))
end
def schedule_deletion(backup) do

View file

@ -29,7 +29,7 @@ def enqueue(args) do
@impl Oban.Worker
def timeout(_job) do
Pleroma.Config.get([:workers, :timeout, :activity_expiration]) || :timer.minutes(1)
Pleroma.Config.get([:workers, :timeout, :activity_expiration], :timer.minutes(1))
end
@impl true

View file

@ -26,7 +26,7 @@ def enqueue(args) do
@impl Oban.Worker
def timeout(_job) do
Pleroma.Config.get([:workers, :timeout, :filter_expiration]) || :timer.minutes(1)
Pleroma.Config.get([:workers, :timeout, :filter_expiration], :timer.minutes(1))
end
@impl true

View file

@ -21,7 +21,7 @@ def enqueue(args) do
@impl Oban.Worker
def timeout(_job) do
Pleroma.Config.get([:workers, :timeout, :token_expiration]) || :timer.minutes(1)
Pleroma.Config.get([:workers, :timeout, :token_expiration], :timer.minutes(1))
end
@impl true

View file

@ -47,7 +47,7 @@ def enqueue(op, params, worker_args \\ []) do
@impl Oban.Worker
def timeout(_job) do
queue_atom = String.to_atom(unquote(queue))
Config.get([:workers, :timeout, queue_atom]) || :timer.minutes(1)
Config.get([:workers, :timeout, queue_atom], :timer.minutes(1))
end
end
end

View file

@ -0,0 +1,52 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Workers.PublisherWorkerTest do
use Pleroma.DataCase, async: true
use Oban.Testing, repo: Pleroma.Repo
import Pleroma.Factory
alias Pleroma.Object
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Builder
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.Federator
describe "Oban job priority:" do
setup do
user = insert(:user)
{:ok, post} = CommonAPI.post(user, %{status: "Regrettable post"})
object = Object.normalize(post, fetch: false)
{:ok, delete_data, _meta} = Builder.delete(user, object.data["id"])
{:ok, delete, _meta} = ActivityPub.persist(delete_data, local: true)
%{
post: post,
delete: delete
}
end
test "Deletions are lower priority", %{delete: delete} do
assert {:ok, %Oban.Job{priority: 3}} = Federator.publish(delete)
end
test "Creates are normal priority", %{post: post} do
assert {:ok, %Oban.Job{priority: 0}} = Federator.publish(post)
end
end
describe "Oban job timeout" do
test "should have a timeout" do
clear_config([:workers, :timeout, :federator_outgoing], :timer.minutes(2))
assert Pleroma.Workers.PublisherWorker.timeout(nil) == :timer.minutes(2)
end
test "should use a default timeout if none specified" do
clear_config([:workers, :timeout, :federator_outgoing])
assert Pleroma.Workers.PublisherWorker.timeout(nil) == :timer.seconds(10)
end
end
end