Add logging to HRRR fetch and parse pipeline
This commit is contained in:
parent
ead34990b0
commit
38bfd7caed
2 changed files with 17 additions and 0 deletions
|
|
@ -3,6 +3,8 @@ defmodule Microwaveprop.Weather.HrrrClient do
|
|||
|
||||
alias Microwaveprop.Weather.Grib2.Extractor
|
||||
|
||||
require Logger
|
||||
|
||||
@hrrr_base "https://noaa-hrrr-bdp-pds.s3.amazonaws.com"
|
||||
|
||||
@pressure_levels [1000, 975, 950, 925, 900, 850, 800, 700]
|
||||
|
|
@ -138,10 +140,14 @@ defmodule Microwaveprop.Weather.HrrrClient do
|
|||
:pressure -> pressure_messages()
|
||||
end
|
||||
|
||||
Logger.info("HRRR fetching #{product} idx from #{idx_url}")
|
||||
|
||||
with {:ok, idx_text} <- fetch_idx(idx_url),
|
||||
idx_entries = parse_idx(idx_text),
|
||||
ranges = byte_ranges_for_messages(idx_entries, wanted),
|
||||
_ = Logger.info("HRRR downloading #{length(ranges)} GRIB ranges for #{product}"),
|
||||
{:ok, grib_binary} <- download_grib_ranges(url, ranges) do
|
||||
Logger.info("HRRR #{product} downloaded #{byte_size(grib_binary)} bytes, extracting")
|
||||
Extractor.extract_points(grib_binary, lat, lon)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ defmodule Microwaveprop.Workers.HrrrFetchWorker do
|
|||
alias Microwaveprop.Weather.HrrrClient
|
||||
alias Microwaveprop.Weather.SoundingParams
|
||||
|
||||
require Logger
|
||||
|
||||
@impl Oban.Worker
|
||||
def backoff(%Oban.Job{attempt: attempt}) do
|
||||
# Exponential backoff: 2m, 4m, 8m, 16m, 32m, 1h, 2h, 4h, 6h, 6h, ...
|
||||
|
|
@ -20,11 +22,15 @@ defmodule Microwaveprop.Workers.HrrrFetchWorker do
|
|||
{lat, lon} = Weather.round_to_hrrr_grid(raw_lat, raw_lon)
|
||||
|
||||
if Weather.has_hrrr_profile?(lat, lon, valid_time) do
|
||||
Logger.info("HRRR profile already exists for #{lat},#{lon} @ #{valid_time_str}")
|
||||
:ok
|
||||
else
|
||||
Logger.info("Fetching HRRR profile for #{lat},#{lon} @ #{valid_time_str}")
|
||||
|
||||
case HrrrClient.fetch_profile(lat, lon, valid_time) do
|
||||
{:ok, data} ->
|
||||
params = SoundingParams.derive(data.profile)
|
||||
levels = length(data.profile)
|
||||
|
||||
attrs =
|
||||
maybe_add_derived_params(
|
||||
|
|
@ -44,12 +50,17 @@ defmodule Microwaveprop.Workers.HrrrFetchWorker do
|
|||
)
|
||||
|
||||
Weather.upsert_hrrr_profile(attrs)
|
||||
|
||||
Logger.info("HRRR profile saved for #{lat},#{lon} @ #{valid_time_str} (#{levels} levels, run #{data.run_time})")
|
||||
|
||||
:ok
|
||||
|
||||
{:error, reason} ->
|
||||
if permanent_failure?(reason) do
|
||||
Logger.warning("HRRR permanent failure for #{lat},#{lon} @ #{valid_time_str}: #{inspect(reason)}")
|
||||
{:cancel, reason}
|
||||
else
|
||||
Logger.error("HRRR fetch error for #{lat},#{lon} @ #{valid_time_str}: #{inspect(reason)}")
|
||||
{:error, reason}
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue