Fix cancelling jobs
This commit is contained in:
parent
74072622e0
commit
8893ad9899
@ -714,11 +714,11 @@ defmodule Pleroma.Web.CommonAPI 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
|
||||||
|
|
||||||
|
@ -1957,7 +1957,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||||||
{: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 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||||||
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 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||||||
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 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||||||
|> 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 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||||||
{: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 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||||||
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 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||||||
|> 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 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||||||
{: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 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||||||
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 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||||||
|> 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 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||||||
{: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 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||||||
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 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||||||
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 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||||||
|> 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
|
||||||
|
Loading…
Reference in New Issue
Block a user