Clean up ReachabilityWorker jobs and delete from Instances table when deleting all users and activities for an instance
This commit is contained in:
parent
29f7607910
commit
f06f0bedd3
3 changed files with 23 additions and 5 deletions
|
|
@ -99,11 +99,7 @@ defmodule Pleroma.Instances.Instance do
|
|||
|> changeset(%{unreachable_since: nil})
|
||||
|> Repo.insert(on_conflict: {:replace, [:unreachable_since]}, conflict_target: :host)
|
||||
|
||||
# Delete any existing reachability testing jobs for this instance
|
||||
Oban.Job
|
||||
|> Ecto.Query.where(worker: "Pleroma.Workers.ReachabilityWorker")
|
||||
|> Ecto.Query.where([j], j.args["domain"] == ^host)
|
||||
|> Oban.delete_all_jobs()
|
||||
Pleroma.Workers.ReachabilityWorker.delete_jobs_for_host(host)
|
||||
|
||||
result
|
||||
end
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ defmodule Pleroma.Workers.DeleteWorker do
|
|||
end
|
||||
|
||||
def perform(%Job{args: %{"op" => "delete_instance", "host" => host}}) do
|
||||
# Schedule the per-user deletion jobs
|
||||
Pleroma.Repo.transaction(fn ->
|
||||
User.Query.build(%{nickname: "@#{host}"})
|
||||
|> Pleroma.Repo.all()
|
||||
|
|
@ -22,6 +23,17 @@ defmodule Pleroma.Workers.DeleteWorker do
|
|||
|> __MODULE__.new()
|
||||
|> Oban.insert()
|
||||
end)
|
||||
|
||||
# Delete the instance from the Instances table
|
||||
case Pleroma.Repo.get_by(Pleroma.Instances.Instance, host: host) do
|
||||
nil -> :ok
|
||||
instance -> Pleroma.Repo.delete(instance)
|
||||
end
|
||||
|
||||
# Delete any pending ReachabilityWorker jobs for this domain
|
||||
Pleroma.Workers.ReachabilityWorker.delete_jobs_for_host(host)
|
||||
|
||||
:ok
|
||||
end)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@ defmodule Pleroma.Workers.ReachabilityWorker do
|
|||
alias Pleroma.HTTP
|
||||
alias Pleroma.Instances
|
||||
|
||||
import Ecto.Query
|
||||
|
||||
@impl true
|
||||
def perform(%Oban.Job{args: %{"domain" => domain, "phase" => phase, "attempt" => attempt}}) do
|
||||
case check_reachability(domain) do
|
||||
|
|
@ -43,6 +45,14 @@ defmodule Pleroma.Workers.ReachabilityWorker do
|
|||
@impl true
|
||||
def timeout(_job), do: :timer.seconds(5)
|
||||
|
||||
@doc "Deletes scheduled jobs to check reachability for specified instance"
|
||||
def delete_jobs_for_host(host) do
|
||||
Oban.Job
|
||||
|> where(worker: "Pleroma.Workers.ReachabilityWorker")
|
||||
|> where([j], j.args["domain"] == ^host)
|
||||
|> Oban.delete_all_jobs()
|
||||
end
|
||||
|
||||
defp check_reachability(domain) do
|
||||
case HTTP.get("https://#{domain}/") do
|
||||
{:ok, %{status: status}} when status in 200..299 ->
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue