Ensure ReachabilityWorker jobs can be scheduled without needing awareness of the phase design
This commit is contained in:
parent
ff5f88aae3
commit
2267ace106
2 changed files with 40 additions and 0 deletions
|
|
@ -24,6 +24,22 @@ defmodule Pleroma.Workers.ReachabilityWorker do
|
|||
end
|
||||
end
|
||||
|
||||
# New jobs enter here and are immediately re-scheduled for the first phase
|
||||
@impl true
|
||||
def perform(%Oban.Job{args: %{"domain" => domain}}) do
|
||||
scheduled_at = DateTime.add(DateTime.utc_now(), 60, :second)
|
||||
|
||||
%{
|
||||
"domain" => domain,
|
||||
"phase" => "phase_1min",
|
||||
"attempt" => 1
|
||||
}
|
||||
|> new(scheduled_at: scheduled_at, replace: true)
|
||||
|> Oban.insert()
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
@impl true
|
||||
def timeout(_job), do: :timer.seconds(5)
|
||||
|
||||
|
|
|
|||
|
|
@ -191,6 +191,30 @@ defmodule Pleroma.Workers.ReachabilityWorkerTest do
|
|||
assert existing_job.args["domain"] == domain
|
||||
assert existing_job.args["phase"] == "phase_1min"
|
||||
end
|
||||
|
||||
test "handles new jobs with only domain argument and transitions them to the first phase" do
|
||||
domain = "legacy.example.com"
|
||||
|
||||
with_mocks([
|
||||
{Pleroma.Instances, [], [set_reachable: fn _ -> :ok end]}
|
||||
]) do
|
||||
# Create a job with only domain (legacy format)
|
||||
job = %Oban.Job{
|
||||
args: %{"domain" => domain}
|
||||
}
|
||||
|
||||
# Should reschedule with phase_1min and attempt 1
|
||||
assert :ok = ReachabilityWorker.perform(job)
|
||||
|
||||
# Check that a new job was scheduled with the correct format
|
||||
scheduled_jobs = all_enqueued(worker: ReachabilityWorker)
|
||||
assert length(scheduled_jobs) == 1
|
||||
[scheduled_job] = scheduled_jobs
|
||||
assert scheduled_job.args["domain"] == domain
|
||||
assert scheduled_job.args["phase"] == "phase_1min"
|
||||
assert scheduled_job.args["attempt"] == 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
defp get_phase_config("phase_1min"), do: {1, 4, "phase_15min"}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue