mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-11-09 17:55:11 +00:00
and i yoink (#275)
Co-authored-by: Mark Felder <feld@feld.me> Co-authored-by: FloatingGhost <hannah@coffee-and-dreams.uk> Reviewed-on: https://akkoma.dev/AkkomaGang/akkoma/pulls/275
This commit is contained in:
parent
893bfde66f
commit
2a1f17e3ed
|
@ -48,7 +48,9 @@ defmodule Pleroma.Web.Federator do
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def publish(%{data: %{"object" => object}} = activity) when is_binary(object) do
|
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
|
end
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
|
@ -63,7 +65,7 @@ defmodule Pleroma.Web.Federator do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp publish_priority(%{type: "Delete"}), do: 3
|
defp publish_priority(%{data: %{"type" => "Delete"}}), do: 3
|
||||||
defp publish_priority(_), do: 0
|
defp publish_priority(_), do: 0
|
||||||
|
|
||||||
# Job Worker Callbacks
|
# Job Worker Callbacks
|
||||||
|
|
|
@ -16,7 +16,7 @@ defmodule Pleroma.Workers.BackupWorker do
|
||||||
|
|
||||||
@impl Oban.Worker
|
@impl Oban.Worker
|
||||||
def timeout(_job) do
|
def timeout(_job) do
|
||||||
Pleroma.Config.get([:workers, :timeout, :backup]) || :timer.minutes(1)
|
Pleroma.Config.get([:workers, :timeout, :backup], :timer.minutes(1))
|
||||||
end
|
end
|
||||||
|
|
||||||
def schedule_deletion(backup) do
|
def schedule_deletion(backup) do
|
||||||
|
|
|
@ -29,7 +29,7 @@ defmodule Pleroma.Workers.PurgeExpiredActivity do
|
||||||
|
|
||||||
@impl Oban.Worker
|
@impl Oban.Worker
|
||||||
def timeout(_job) do
|
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
|
end
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
|
|
|
@ -26,7 +26,7 @@ defmodule Pleroma.Workers.PurgeExpiredFilter do
|
||||||
|
|
||||||
@impl Oban.Worker
|
@impl Oban.Worker
|
||||||
def timeout(_job) do
|
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
|
end
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
|
|
|
@ -21,7 +21,7 @@ defmodule Pleroma.Workers.PurgeExpiredToken do
|
||||||
|
|
||||||
@impl Oban.Worker
|
@impl Oban.Worker
|
||||||
def timeout(_job) do
|
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
|
end
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
|
|
|
@ -47,7 +47,7 @@ defmodule Pleroma.Workers.WorkerHelper do
|
||||||
@impl Oban.Worker
|
@impl Oban.Worker
|
||||||
def timeout(_job) do
|
def timeout(_job) do
|
||||||
queue_atom = String.to_atom(unquote(queue))
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
52
test/pleroma/workers/publisher_worker_test.exs
Normal file
52
test/pleroma/workers/publisher_worker_test.exs
Normal 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
|
Loading…
Reference in a new issue