Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Features/handle gohan errors #49

Merged
merged 7 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions bento_beacon/utils/beacon_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,9 @@ def received_request():
def build_response_meta():
returned_schemas = g.get("response_data", {}).get("returnedSchemas", [])
returned_granularity = g.get("response_data", {}).get("returnedGranularity", "count")
service_info = current_app.config["BEACON_CONFIG"].get("serviceInfo")
received_request_summary = received_request()
return {
"beaconId": service_info.get("id"),
"beaconId": current_app.config["BEACON_ID"],
"apiVersion": current_app.config["BEACON_SPEC_VERSION"],
"returnedSchemas": returned_schemas,
"returnedGranularity": returned_granularity,
Expand All @@ -127,9 +126,8 @@ def build_response_meta():


def build_info_response_meta():
service_info = current_app.config["BEACON_CONFIG"].get("serviceInfo")
return {
"beaconId": service_info.get("id"),
"beaconId": current_app.config["BEACON_ID"],
"apiVersion": current_app.config["BEACON_SPEC_VERSION"],
"returnedSchemas": []
}
Expand Down
26 changes: 21 additions & 5 deletions bento_beacon/utils/gohan_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def gohan_network_call(url, gohan_args):
gohan_response = r.json()

except requests.exceptions.RequestException as e:
current_app.logger.debug(f"gohan error: {e}")
current_app.logger.error(f"gohan error: {e}")
raise APIException(message="error calling gohan variants service")

return gohan_response
Expand Down Expand Up @@ -228,13 +228,29 @@ def gohan_counts_by_assembly_id():
return gohan_overview().get("assemblyIDs", {})


# gohan /variants/overview hangs when no variants table
# so check for a table before calling
# only runs if "useGohan" true
def gohan_counts_for_overview():
# gohan /variants/overview hangs when no variants table
# so check for tables before calling
tables_url = current_app.config["GOHAN_BASE_URL"] + "/tables?data-type=variant"
has_tables = gohan_network_call(tables_url, {})
if has_tables:
tables = None

try:
tables = gohan_network_call(tables_url, {})
except APIException:
# note this exception but don't rethrow
current_app.logger.error("cannot reach gohan for overview")

# non-empty tables
if tables:
return gohan_counts_by_assembly_id()

# empty tables (fresh instance or elasticsearch down)
# "useGohan" is true here so we expect variants to exist
if tables is not None:
return {"error": "no variants available"}

# else bad response from gohan
return {"error": "gohan unavailable"}

# --------------------------------------------
Expand Down