Skip to content

Commit e6e92f9

Browse files
authored
Merge pull request #821 from hubmapconsortium/karlburke/stashLargeDescendantsRespInS3
Stash large descendants responses in S3
2 parents 2045a2b + 21fd438 commit e6e92f9

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

entity-api-spec.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ components:
324324
properties:
325325
organ_donor_data:
326326
type: array
327-
description: "Information about the donor who's organ(s) was/were used. The organ was obtained via an organ donation program from a deceaced donor. Only living_donor_data or organ_donor_data, not both can be defined for a single donor."
327+
description: "Information about the donor who's organ(s) was/were used. The organ was obtained via an organ donation program from a deceased donor. Only living_donor_data or organ_donor_data, not both can be defined for a single donor."
328328
items:
329329
$ref: '#/components/schemas/DonorMetadata'
330330
living_donor_data:
@@ -2100,6 +2100,8 @@ paths:
21002100
examples:
21012101
ancestorsarray:
21022102
$ref: '#/components/examples/DatasetArrayExample'
2103+
'303':
2104+
description: If the total response payload exceeds 10 MB, the response is returned via an S3 bucket. A 303 HTTP response code will be returned with the redirect URL where the query can be retrieved.
21032105
'400':
21042106
description: Invalid or misformatted entity identifier
21052107
'401':

src/app.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,6 +1664,8 @@ def get_ancestors(id):
16641664
"""
16651665
@app.route('/descendants/<id>', methods = ['GET'])
16661666
def get_descendants(id):
1667+
global anS3Worker
1668+
16671669
final_result = []
16681670

16691671
# Get user token from Authorization header
@@ -1718,6 +1720,25 @@ def get_descendants(id):
17181720
# Final result after normalization
17191721
final_result = schema_manager.normalize_entities_list_for_response(complete_entities_list)
17201722

1723+
# Check the size of what is to be returned through the AWS Gateway, and replace it with
1724+
# a response that links to an Object in the AWS S3 Bucket, if appropriate.
1725+
try:
1726+
resp_body = json.dumps(final_result).encode('utf-8')
1727+
s3_url = anS3Worker.stash_response_body_if_big(resp_body)
1728+
if s3_url is not None:
1729+
return Response(response=s3_url
1730+
, status=303) # See Other
1731+
# The HuBMAP Commons S3Worker will return None for a URL when the response body is
1732+
# smaller than it is configured to store, so the response should be returned through
1733+
# the AWS Gateway
1734+
except Exception as s3exception:
1735+
logger.error(f"Error using anS3Worker to handle len(resp_body)="
1736+
f"{len(resp_body)}.")
1737+
logger.error(s3exception, exc_info=True)
1738+
return Response(response=f"Unexpected error storing large results in S3. See logs."
1739+
, status=500)
1740+
1741+
# Return a regular response through the AWS Gateway
17211742
return jsonify(final_result)
17221743

17231744

0 commit comments

Comments
 (0)