Skip to content

Commit

Permalink
Don't clear entire requests_cache cache when polling the website
Browse files Browse the repository at this point in the history
This is better as we don't lose the cache from other calls, but we do still get fresh data from the website poll.

As a side-effect, we lose the INFO log messages which closes nf-core#1029
  • Loading branch information
ewels committed May 6, 2021
1 parent da71010 commit c18db08
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions nf_core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,36 +329,36 @@ def poll_nfcore_web_api(api_url, post_data=None):
Expects API reponse to be valid JSON and contain a top-level 'status' key.
"""
# Clear requests_cache so that we get the updated statuses
requests_cache.clear()
try:
if post_data is None:
response = requests.get(api_url, headers={"Cache-Control": "no-cache"})
else:
response = requests.post(url=api_url, data=post_data)
except (requests.exceptions.Timeout):
raise AssertionError("URL timed out: {}".format(api_url))
except (requests.exceptions.ConnectionError):
raise AssertionError("Could not connect to URL: {}".format(api_url))
else:
if response.status_code != 200:
log.debug("Response content:\n{}".format(response.content))
raise AssertionError(
"Could not access remote API results: {} (HTML {} Error)".format(api_url, response.status_code)
)
# Run without requests_cache so that we get the updated statuses
with requests_cache.disabled():
try:
if post_data is None:
response = requests.get(api_url, headers={"Cache-Control": "no-cache"})
else:
response = requests.post(url=api_url, data=post_data)
except (requests.exceptions.Timeout):
raise AssertionError("URL timed out: {}".format(api_url))
except (requests.exceptions.ConnectionError):
raise AssertionError("Could not connect to URL: {}".format(api_url))
else:
try:
web_response = json.loads(response.content)
assert "status" in web_response
except (json.decoder.JSONDecodeError, AssertionError, TypeError) as e:
if response.status_code != 200:
log.debug("Response content:\n{}".format(response.content))
raise AssertionError(
"nf-core website API results response not recognised: {}\n See verbose log for full response".format(
api_url
)
"Could not access remote API results: {} (HTML {} Error)".format(api_url, response.status_code)
)
else:
return web_response
try:
web_response = json.loads(response.content)
assert "status" in web_response
except (json.decoder.JSONDecodeError, AssertionError, TypeError) as e:
log.debug("Response content:\n{}".format(response.content))
raise AssertionError(
"nf-core website API results response not recognised: {}\n See verbose log for full response".format(
api_url
)
)
else:
return web_response


def anaconda_package(dep, dep_channels=["conda-forge", "bioconda", "defaults"]):
Expand Down

0 comments on commit c18db08

Please sign in to comment.