Skip to content

Commit

Permalink
retry glider data fecthing 3x, while waiting 5 s.
Browse files Browse the repository at this point in the history
  • Loading branch information
ocefpaf committed Jan 28, 2025
1 parent c73567a commit af79d8b
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions ioos_metrics/ioos_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from fake_useragent import UserAgent
from gliderpy.fetchers import GliderDataFetcher
from shapely.geometry import LineString, Point
from tenacity import retry, stop_after_attempt, wait_fixed

from ioos_metrics.national_platforms import national_platforms

Expand Down Expand Up @@ -223,6 +224,7 @@ def _make_track_geom(df) -> "pd.DataFrame":
)
)

@retry(stop=stop_after_attempt(3), wait=wait_fixed(5))
def _computed_metadata(dataset_id) -> dict:
"""Download the minimum amount of data possible for the computed
metadata.
Expand Down Expand Up @@ -269,15 +271,12 @@ def _computed_metadata(dataset_id) -> dict:
for _, row in list(df.iterrows()):
dataset_id = row["Dataset ID"]
info_url = row["info_url"].replace("html", "csv")
info_df = pd.read_csv(info_url)
info = _metadata(info_df)
try:
info_df = pd.read_csv(info_url)
info = _metadata(info_df)
info.update(_computed_metadata(dataset_id=dataset_id))
except (httpx.HTTPError, httpx.HTTPStatusError):
print( # noqa: T201
f"Could not fetch glider {dataset_id=}. "
"This could be a server side error and the metrics will be incomplete!",
)
except (httpx.HTTPError, httpx.HTTPStatusError, ValueError) as e:
print(f"Could not fetch glider {dataset_id=}.\n{e=}") # noqa: T201
continue
metadata.update({dataset_id: info})
return pd.DataFrame(metadata).T
Expand Down

0 comments on commit af79d8b

Please sign in to comment.