Skip to content

Commit

Permalink
better diagnostics for development
Browse files Browse the repository at this point in the history
  • Loading branch information
wumpus committed Feb 8, 2022
1 parent 790767d commit c1ff75d
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions eht_met_forecast/gfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def fetch_gfs_download(url, params, wait=False, verbose=False, stats=None):

retry = MAX_DOWNLOAD_TRIES
actual_tries = 0
r = None # so we can use it even after an exception
while retry > 0:
try:
actual_tries += 1
Expand Down Expand Up @@ -106,10 +107,12 @@ def fetch_gfs_download(url, params, wait=False, verbose=False, stats=None):
# allow_redirects=True is the default for .get() so by default the redir will be followed
# so a 302 shouldn't be visible
errflag = 1
print('should not happen: 302 with Location: {} seen'.format(r.headers['Location']), file=sys.stderr, end='')
if stats:
stats['302_with_location'] += 1
elif r.status_code in {500, 502, 504}:
# I've seen 502 from NOMADS when the website is broken
# 500s when the lev_ or var_ are incorrect, detailed message in the contents
errflag = 1
print('Received retryable status ({})'.format(r.status_code), file=sys.stderr, end='')
retry += 0.8 # this counts as 1/5 of a retry
Expand Down Expand Up @@ -149,6 +152,11 @@ def fetch_gfs_download(url, params, wait=False, verbose=False, stats=None):
retry = retry - 1
if retry > 0:
print(" Retrying...", file=sys.stderr)
if r:
try: # I don't think this can fail, but anyway
print(' Content was:', r.content[:100])
except Exception:
pass
time.sleep(retry_duration)
else:
print(" Giving up.", file=sys.stderr)
Expand Down

0 comments on commit c1ff75d

Please sign in to comment.