Instance.set_reachable/1 should delete any existing ReachabilityWorker jobs for that instance
This commit is contained in:
parent
13db730659
commit
ff5f88aae3
2 changed files with 40 additions and 3 deletions
|
|
@ -92,9 +92,20 @@ defmodule Pleroma.Instances.Instance do
|
||||||
def reachable?(url_or_host) when is_binary(url_or_host), do: true
|
def reachable?(url_or_host) when is_binary(url_or_host), do: true
|
||||||
|
|
||||||
def set_reachable(url_or_host) when is_binary(url_or_host) do
|
def set_reachable(url_or_host) when is_binary(url_or_host) do
|
||||||
%Instance{host: host(url_or_host)}
|
host = host(url_or_host)
|
||||||
|
|
||||||
|
result =
|
||||||
|
%Instance{host: host}
|
||||||
|> changeset(%{unreachable_since: nil})
|
|> changeset(%{unreachable_since: nil})
|
||||||
|> Repo.insert(on_conflict: {:replace, [:unreachable_since]}, conflict_target: :host)
|
|> 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()
|
||||||
|
|
||||||
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_reachable(_), do: {:error, nil}
|
def set_reachable(_), do: {:error, nil}
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,32 @@ defmodule Pleroma.Instances.InstanceTest do
|
||||||
assert {:ok, instance} = Instance.set_reachable(instance.host)
|
assert {:ok, instance} = Instance.set_reachable(instance.host)
|
||||||
refute instance.unreachable_since
|
refute instance.unreachable_since
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "cancels all ReachabilityWorker jobs for the domain" do
|
||||||
|
domain = "cancelme.example.org"
|
||||||
|
insert(:instance, host: domain, unreachable_since: NaiveDateTime.utc_now())
|
||||||
|
|
||||||
|
# Insert a ReachabilityWorker job for this domain, scheduled 5 minutes in the future
|
||||||
|
scheduled_at = DateTime.add(DateTime.utc_now(), 300, :second)
|
||||||
|
|
||||||
|
{:ok, job} =
|
||||||
|
Pleroma.Workers.ReachabilityWorker.new(
|
||||||
|
%{"domain" => domain, "phase" => "phase_1min", "attempt" => 1},
|
||||||
|
scheduled_at: scheduled_at
|
||||||
|
)
|
||||||
|
|> Oban.insert()
|
||||||
|
|
||||||
|
# Ensure the job is present
|
||||||
|
job = Pleroma.Repo.get(Oban.Job, job.id)
|
||||||
|
assert job
|
||||||
|
|
||||||
|
# Call set_reachable, which should delete the job
|
||||||
|
assert {:ok, _} = Instance.set_reachable(domain)
|
||||||
|
|
||||||
|
# Reload the job and assert it is deleted
|
||||||
|
job = Pleroma.Repo.get(Oban.Job, job.id)
|
||||||
|
refute job
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "set_unreachable/1" do
|
describe "set_unreachable/1" do
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue