about summary refs log tree commit diff
path: root/gn3/api/streaming.py
diff options
context:
space:
mode:
authorAlexander Kabui2025-01-11 08:33:51 +0300
committerGitHub2025-01-11 08:33:51 +0300
commite501df4458080cd4a39f3124c7e13dacd9d9f28a (patch)
tree6556b96aece75fddf563753b5e089a6608fbd88c /gn3/api/streaming.py
parent677d68c4b56585b29227efb9821ca674951411ca (diff)
parent200deff652bfae364d6e15ff2bceefdc1686f158 (diff)
downloadgenenetwork3-e501df4458080cd4a39f3124c7e13dacd9d9f28a.tar.gz
Merge pull request #206 from genenetwork/enhancements/streaming-modularization
Enhancements/streaming modularization
Diffstat (limited to 'gn3/api/streaming.py')
-rw-r--r--gn3/api/streaming.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/gn3/api/streaming.py b/gn3/api/streaming.py
new file mode 100644
index 0000000..2b6b431
--- /dev/null
+++ b/gn3/api/streaming.py
@@ -0,0 +1,26 @@
+""" File contains endpoint for computational streaming"""
+import os
+from flask import current_app
+from flask import jsonify
+from flask import Blueprint
+from flask import request
+
+streaming = Blueprint("stream", __name__)
+
+
+@streaming.route("/<identifier>",  methods=["GET"])
+def stream(identifier):
+    """ This endpoint streams stdout from a file.
+    It expects the identifier to be the filename
+    in the TMPDIR created at the main computation
+    endpoint see example api/rqtl."""
+    output_file = os.path.join(current_app.config.get("TMPDIR"),
+                               f"{identifier}.txt")
+    seek_position = int(request.args.get("peak", 0))
+    with open(output_file, encoding="utf-8") as file_handler:
+        # read from the last  read position default to 0
+        file_handler.seek(seek_position)
+        results = {"data": file_handler.readlines(),
+                   "run_id": identifier,
+                   "pointer": file_handler.tell()}
+        return jsonify(results)