Add logging to WeatherFetchWorker for ASOS and RAOB fetches
This commit is contained in:
parent
7fd8f3165c
commit
8d008ba934
1 changed files with 19 additions and 0 deletions
|
|
@ -5,6 +5,8 @@ defmodule Microwaveprop.Workers.WeatherFetchWorker do
|
|||
max_attempts: 20,
|
||||
unique: [period: 300, states: [:available, :scheduled, :executing, :retryable]]
|
||||
|
||||
require Logger
|
||||
|
||||
alias Microwaveprop.Repo
|
||||
alias Microwaveprop.Weather
|
||||
alias Microwaveprop.Weather.IemClient
|
||||
|
|
@ -30,18 +32,26 @@ defmodule Microwaveprop.Workers.WeatherFetchWorker do
|
|||
|
||||
case Repo.get(Station, station_id) do
|
||||
nil ->
|
||||
Logger.warning("WeatherFetch ASOS: station #{station_id} not found, skipping")
|
||||
:ok
|
||||
|
||||
station ->
|
||||
if Weather.has_surface_observations?(station.id, start_dt, end_dt) do
|
||||
Logger.debug("WeatherFetch ASOS: #{station_code} already has obs for #{start_dt_str}..#{end_dt_str}")
|
||||
:ok
|
||||
else
|
||||
Logger.info("WeatherFetch ASOS: fetching #{station_code} for #{start_dt_str}..#{end_dt_str}")
|
||||
|
||||
case IemClient.fetch_asos(station_code, start_dt, end_dt) do
|
||||
{:ok, rows} ->
|
||||
count = Enum.count(rows, & &1.observed_at)
|
||||
|
||||
Enum.each(rows, fn row ->
|
||||
if row.observed_at, do: Weather.upsert_surface_observation(station, row)
|
||||
end)
|
||||
|
||||
Logger.info("WeatherFetch ASOS: #{station_code} ingested #{count} observations")
|
||||
|
||||
Phoenix.PubSub.broadcast(
|
||||
Microwaveprop.PubSub,
|
||||
"contact_enrichment:weather",
|
||||
|
|
@ -51,6 +61,7 @@ defmodule Microwaveprop.Workers.WeatherFetchWorker do
|
|||
:ok
|
||||
|
||||
{:error, reason} ->
|
||||
Logger.warning("WeatherFetch ASOS: #{station_code} failed: #{inspect(reason)}")
|
||||
{:error, reason}
|
||||
end
|
||||
end
|
||||
|
|
@ -68,12 +79,16 @@ defmodule Microwaveprop.Workers.WeatherFetchWorker do
|
|||
|
||||
case Repo.get(Station, station_id) do
|
||||
nil ->
|
||||
Logger.warning("WeatherFetch RAOB: station #{station_id} not found, skipping")
|
||||
:ok
|
||||
|
||||
station ->
|
||||
if Weather.has_sounding?(station.id, sounding_time) do
|
||||
Logger.debug("WeatherFetch RAOB: #{station_code} already has sounding for #{sounding_time_str}")
|
||||
:ok
|
||||
else
|
||||
Logger.info("WeatherFetch RAOB: fetching #{station_code} for #{sounding_time_str}")
|
||||
|
||||
case IemClient.fetch_raob(station_code, sounding_time) do
|
||||
{:ok, [parsed | _]} ->
|
||||
params = SoundingParams.derive(parsed.profile)
|
||||
|
|
@ -106,6 +121,8 @@ defmodule Microwaveprop.Workers.WeatherFetchWorker do
|
|||
|
||||
Weather.upsert_sounding(station, sounding_attrs)
|
||||
|
||||
Logger.info("WeatherFetch RAOB: #{station_code} ingested sounding with #{length(parsed.profile)} levels")
|
||||
|
||||
Phoenix.PubSub.broadcast(
|
||||
Microwaveprop.PubSub,
|
||||
"contact_enrichment:weather",
|
||||
|
|
@ -115,9 +132,11 @@ defmodule Microwaveprop.Workers.WeatherFetchWorker do
|
|||
:ok
|
||||
|
||||
{:ok, []} ->
|
||||
Logger.info("WeatherFetch RAOB: #{station_code} returned no data for #{sounding_time_str}")
|
||||
:ok
|
||||
|
||||
{:error, reason} ->
|
||||
Logger.warning("WeatherFetch RAOB: #{station_code} failed: #{inspect(reason)}")
|
||||
{:error, reason}
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue