Skip to content

Commit

Permalink
Merge pull request #33 from bento-platform/stream-cache
Browse files Browse the repository at this point in the history
Add cache control headers to run streams
  • Loading branch information
davidlougheed authored Feb 15, 2023
2 parents ebe6660 + cd3140f commit 6e10733
Show file tree
Hide file tree
Showing 5 changed files with 215 additions and 117 deletions.
7 changes: 5 additions & 2 deletions bento_wes/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def service_info():
"description": "Workflow execution service for a CHORD application.",
"organization": {
"name": "C3G",
"url": "http://www.computationalgenomics.ca"
"url": "https://www.computationalgenomics.ca"
},
"contactUrl": "mailto:[email protected]",
"version": bento_wes.__version__,
Expand All @@ -87,16 +87,19 @@ def service_info():
if res_tag := subprocess.check_output(["git", "describe", "--tags", "--abbrev=0"]):
res_tag_str = res_tag.decode().rstrip()
info["git_tag"] = res_tag_str
# noinspection PyTypeChecker
info["bento"]["gitTag"] = res_tag_str
if res_branch := subprocess.check_output(["git", "branch", "--show-current"]):
res_branch_str = res_branch.decode().rstrip()
info["git_branch"] = res_branch_str
# noinspection PyTypeChecker
info["bento"]["gitBranch"] = res_branch_str
if res_commit := subprocess.check_output(["git", "rev-parse", "HEAD"]):
res_commit_str = res_commit.decode().rstrip()
# noinspection PyTypeChecker
info["bento"]["gitCommit"] = res_commit_str
except Exception as e:
except_name = type(e).__name__
current_app.logger.error(f"Error retrieving git information: {str(except_name)}: {e}")
current_app.logger.info(f"Could not retrieve git information: {str(except_name)}: {e}")

return jsonify(info)
15 changes: 13 additions & 2 deletions bento_wes/runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,19 @@ def run_detail(run_id):
def get_stream(c, stream, run_id):
c.execute("SELECT * FROM runs AS r, run_logs AS rl WHERE r.id = ? AND r.run_log = rl.id", (str(run_id),))
run = c.fetchone()
return (current_app.response_class(response=run[stream], mimetype="text/plain", status=200) if run is not None
else flask_not_found_error(f"Stream {stream} not found for run {run_id}"))
return (current_app.response_class(
headers={
# If we've finished, we allow long-term (24h) caching of the stdout/stderr responses.
# Otherwise, no caching allowed!
"Cache-Control": (
"private, max-age=86400" if run["state"] in states.TERMINATED_STATES
else "no-cache, no-store, must-revalidate, max-age=0"
),
},
response=run[stream],
mimetype="text/plain",
status=200,
) if run is not None else flask_not_found_error(f"Stream {stream} not found for run {run_id}"))


@bp_runs.route("/runs/<uuid:run_id>/stdout", methods=["GET"])
Expand Down
1 change: 1 addition & 0 deletions bento_wes/states.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@

FAILURE_STATES = frozenset({STATE_EXECUTOR_ERROR, STATE_SYSTEM_ERROR})
SUCCESS_STATES = frozenset({STATE_COMPLETE})
TERMINATED_STATES = FAILURE_STATES.union(SUCCESS_STATES)
Loading

0 comments on commit 6e10733

Please sign in to comment.