Cancel HRRR jobs on permanent failures (404, outside_grid)
HTTP 404 means the HRRR data doesn't exist on NOAA S3 (pre-2014
dates, etc.) and will never succeed. Return {:cancel, reason}
instead of {:error, reason} so Oban stops retrying immediately.
This commit is contained in:
parent
3749360a28
commit
e2f5376355
2 changed files with 29 additions and 1 deletions
|
|
@ -47,11 +47,21 @@ defmodule Microwaveprop.Workers.HrrrFetchWorker do
|
|||
:ok
|
||||
|
||||
{:error, reason} ->
|
||||
{:error, reason}
|
||||
if permanent_failure?(reason) do
|
||||
{:cancel, reason}
|
||||
else
|
||||
{:error, reason}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# 404 means the HRRR data doesn't exist (pre-2014, etc.) — will never succeed
|
||||
defp permanent_failure?("HRRR idx HTTP 404"), do: true
|
||||
defp permanent_failure?("HRRR grib HTTP 404"), do: true
|
||||
defp permanent_failure?(:outside_grid), do: true
|
||||
defp permanent_failure?(_), do: false
|
||||
|
||||
defp maybe_add_derived_params(attrs, nil), do: attrs
|
||||
|
||||
defp maybe_add_derived_params(attrs, params) do
|
||||
|
|
|
|||
|
|
@ -89,6 +89,24 @@ defmodule Microwaveprop.Workers.HrrrFetchWorkerTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "permanent_failure?/1" do
|
||||
test "cancels on 404 idx" do
|
||||
job = %Oban.Job{
|
||||
args: %{
|
||||
"lat" => 32.90,
|
||||
"lon" => -97.04,
|
||||
"valid_time" => "1995-06-15T12:00:00Z"
|
||||
}
|
||||
}
|
||||
|
||||
Req.Test.stub(Microwaveprop.Weather.HrrrClient, fn conn ->
|
||||
Plug.Conn.send_resp(conn, 404, "not found")
|
||||
end)
|
||||
|
||||
assert {:cancel, "HRRR idx HTTP 404"} = HrrrFetchWorker.perform(job)
|
||||
end
|
||||
end
|
||||
|
||||
defp build_profile_attrs(lat, lon, valid_time, client_result) do
|
||||
%{
|
||||
valid_time: valid_time,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue