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