Fix cancelling jobs

This commit is contained in:
Mark Felder 2024-07-29 09:59:35 -04:00
parent 74072622e0
commit 8893ad9899
2 changed files with 18 additions and 18 deletions

View file

@ -714,11 +714,11 @@ def get_user(ap_id, fake_record_fallback \\ true) do
end end
end end
defp maybe_cancel_jobs(%Activity{data: %{"id" => ap_id}}) do defp maybe_cancel_jobs(%Activity{id: activity_id}) do
Oban.Job Oban.Job
|> where([j], j.worker == "Pleroma.Workers.PublisherWorker") |> where([j], j.worker == "Pleroma.Workers.PublisherWorker")
|> where([j], j.args["op"] == "publish_one") |> where([j], j.args["op"] == "publish_one")
|> where([j], j.args["params"]["id"] == ^ap_id) |> where([j], j.args["params"]["activity_id"] == ^activity_id)
|> Oban.cancel_all_jobs() |> Oban.cancel_all_jobs()
end end

View file

@ -1957,7 +1957,7 @@ test "when deleting posts", %{
{:ok, _, _} = Pleroma.User.follow(remote_one, local_user) {:ok, _, _} = Pleroma.User.follow(remote_one, local_user)
{:ok, _, _} = Pleroma.User.follow(remote_two, local_user) {:ok, _, _} = Pleroma.User.follow(remote_two, local_user)
{:ok, %{data: %{"id" => ap_id}} = activity} = {:ok, %{id: activity_id} = _activity} =
CommonAPI.post(local_user, %{status: "Happy Friday everyone!"}) CommonAPI.post(local_user, %{status: "Happy Friday everyone!"})
# Generate the publish_one jobs # Generate the publish_one jobs
@ -1971,7 +1971,7 @@ test "when deleting posts", %{
state: "available", state: "available",
queue: "federator_outgoing", queue: "federator_outgoing",
worker: "Pleroma.Workers.PublisherWorker", worker: "Pleroma.Workers.PublisherWorker",
args: %{"op" => "publish_one", "params" => %{"id" => ^ap_id}} args: %{"op" => "publish_one", "params" => %{"activity_id" => ^activity_id}}
}, },
job job
) )
@ -1980,7 +1980,7 @@ test "when deleting posts", %{
assert length(publish_one_jobs) == 2 assert length(publish_one_jobs) == 2
# The delete should have triggered cancelling the publish_one jobs # The delete should have triggered cancelling the publish_one jobs
assert {:ok, _delete} = CommonAPI.delete(activity.id, local_user) assert {:ok, _delete} = CommonAPI.delete(activity_id, local_user)
# all_enqueued/1 will not return cancelled jobs # all_enqueued/1 will not return cancelled jobs
cancelled_jobs = cancelled_jobs =
@ -1988,7 +1988,7 @@ test "when deleting posts", %{
|> where([j], j.worker == "Pleroma.Workers.PublisherWorker") |> where([j], j.worker == "Pleroma.Workers.PublisherWorker")
|> where([j], j.state == "cancelled") |> where([j], j.state == "cancelled")
|> where([j], j.args["op"] == "publish_one") |> where([j], j.args["op"] == "publish_one")
|> where([j], j.args["params"]["id"] == ^ap_id) |> where([j], j.args["params"]["activity_id"] == ^activity_id)
|> Pleroma.Repo.all() |> Pleroma.Repo.all()
assert length(cancelled_jobs) == 2 assert length(cancelled_jobs) == 2
@ -2001,7 +2001,7 @@ test "when unfavoriting posts", %{
{:ok, activity} = {:ok, activity} =
CommonAPI.post(remote_user, %{status: "I like turtles!"}) CommonAPI.post(remote_user, %{status: "I like turtles!"})
{:ok, %{data: %{"id" => ap_id}} = _favorite} = {:ok, %{id: favorite_id} = _favorite} =
CommonAPI.favorite(activity.id, local_user) CommonAPI.favorite(activity.id, local_user)
# Generate the publish_one jobs # Generate the publish_one jobs
@ -2015,7 +2015,7 @@ test "when unfavoriting posts", %{
state: "available", state: "available",
queue: "federator_outgoing", queue: "federator_outgoing",
worker: "Pleroma.Workers.PublisherWorker", worker: "Pleroma.Workers.PublisherWorker",
args: %{"op" => "publish_one", "params" => %{"id" => ^ap_id}} args: %{"op" => "publish_one", "params" => %{"activity_id" => ^favorite_id}}
}, },
job job
) )
@ -2032,7 +2032,7 @@ test "when unfavoriting posts", %{
|> where([j], j.worker == "Pleroma.Workers.PublisherWorker") |> where([j], j.worker == "Pleroma.Workers.PublisherWorker")
|> where([j], j.state == "cancelled") |> where([j], j.state == "cancelled")
|> where([j], j.args["op"] == "publish_one") |> where([j], j.args["op"] == "publish_one")
|> where([j], j.args["params"]["id"] == ^ap_id) |> where([j], j.args["params"]["activity_id"] == ^favorite_id)
|> Pleroma.Repo.all() |> Pleroma.Repo.all()
assert length(cancelled_jobs) == 1 assert length(cancelled_jobs) == 1
@ -2049,7 +2049,7 @@ test "when unboosting posts", %{
{:ok, activity} = {:ok, activity} =
CommonAPI.post(remote_one, %{status: "This is an unpleasant post"}) CommonAPI.post(remote_one, %{status: "This is an unpleasant post"})
{:ok, %{data: %{"id" => ap_id}} = _repeat} = {:ok, %{id: repeat_id} = _repeat} =
CommonAPI.repeat(activity.id, local_user) CommonAPI.repeat(activity.id, local_user)
# Generate the publish_one jobs # Generate the publish_one jobs
@ -2063,7 +2063,7 @@ test "when unboosting posts", %{
state: "available", state: "available",
queue: "federator_outgoing", queue: "federator_outgoing",
worker: "Pleroma.Workers.PublisherWorker", worker: "Pleroma.Workers.PublisherWorker",
args: %{"op" => "publish_one", "params" => %{"id" => ^ap_id}} args: %{"op" => "publish_one", "params" => %{"activity_id" => ^repeat_id}}
}, },
job job
) )
@ -2080,7 +2080,7 @@ test "when unboosting posts", %{
|> where([j], j.worker == "Pleroma.Workers.PublisherWorker") |> where([j], j.worker == "Pleroma.Workers.PublisherWorker")
|> where([j], j.state == "cancelled") |> where([j], j.state == "cancelled")
|> where([j], j.args["op"] == "publish_one") |> where([j], j.args["op"] == "publish_one")
|> where([j], j.args["params"]["id"] == ^ap_id) |> where([j], j.args["params"]["activity_id"] == ^repeat_id)
|> Pleroma.Repo.all() |> Pleroma.Repo.all()
assert length(cancelled_jobs) == 2 assert length(cancelled_jobs) == 2
@ -2094,11 +2094,11 @@ test "when unreacting to posts", %{
{:ok, _, _} = Pleroma.User.follow(remote_one, local_user) {:ok, _, _} = Pleroma.User.follow(remote_one, local_user)
{:ok, _, _} = Pleroma.User.follow(remote_two, local_user) {:ok, _, _} = Pleroma.User.follow(remote_two, local_user)
{:ok, activity} = {:ok, %{id: activity_id}} =
CommonAPI.post(remote_one, %{status: "Gang gang!!!!"}) CommonAPI.post(remote_one, %{status: "Gang gang!!!!"})
{:ok, %{data: %{"id" => ap_id}} = _react} = {:ok, %{id: react_id} = _react} =
CommonAPI.react_with_emoji(activity.id, local_user, "👍") CommonAPI.react_with_emoji(activity_id, local_user, "👍")
# Generate the publish_one jobs # Generate the publish_one jobs
ObanHelpers.perform_all() ObanHelpers.perform_all()
@ -2111,7 +2111,7 @@ test "when unreacting to posts", %{
state: "available", state: "available",
queue: "federator_outgoing", queue: "federator_outgoing",
worker: "Pleroma.Workers.PublisherWorker", worker: "Pleroma.Workers.PublisherWorker",
args: %{"op" => "publish_one", "params" => %{"id" => ^ap_id}} args: %{"op" => "publish_one", "params" => %{"activity_id" => ^react_id}}
}, },
job job
) )
@ -2120,7 +2120,7 @@ test "when unreacting to posts", %{
assert length(publish_one_jobs) == 2 assert length(publish_one_jobs) == 2
# The unreact should have triggered cancelling the publish_one jobs # The unreact should have triggered cancelling the publish_one jobs
assert {:ok, _unreact} = CommonAPI.unreact_with_emoji(activity.id, local_user, "👍") assert {:ok, _unreact} = CommonAPI.unreact_with_emoji(activity_id, local_user, "👍")
# all_enqueued/1 will not return cancelled jobs # all_enqueued/1 will not return cancelled jobs
cancelled_jobs = cancelled_jobs =
@ -2128,7 +2128,7 @@ test "when unreacting to posts", %{
|> where([j], j.worker == "Pleroma.Workers.PublisherWorker") |> where([j], j.worker == "Pleroma.Workers.PublisherWorker")
|> where([j], j.state == "cancelled") |> where([j], j.state == "cancelled")
|> where([j], j.args["op"] == "publish_one") |> where([j], j.args["op"] == "publish_one")
|> where([j], j.args["params"]["id"] == ^ap_id) |> where([j], j.args["params"]["activity_id"] == ^react_id)
|> Pleroma.Repo.all() |> Pleroma.Repo.all()
assert length(cancelled_jobs) == 2 assert length(cancelled_jobs) == 2