diff options
| author | Alexander_Kabui | 2025-01-09 10:22:50 +0300 |
|---|---|---|
| committer | Alexander_Kabui | 2025-01-09 10:22:50 +0300 |
| commit | 8bfe9616012deab8f910e89b233ea819ec22c1c3 (patch) | |
| tree | c03d4d02053ee4b52ae8a1440d43c9dd270d2425 | |
| parent | 5515c4de5f0398ba7d4c60d1386963d018a91aa2 (diff) | |
| download | genenetwork3-8bfe9616012deab8f910e89b233ea819ec22c1c3.tar.gz | |
feat: Add streaming main endpoint.
| -rw-r--r-- | gn3/api/streaming.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/gn3/api/streaming.py b/gn3/api/streaming.py index 7c9254a..6569ceb 100644 --- a/gn3/api/streaming.py +++ b/gn3/api/streaming.py @@ -1 +1,24 @@ """ 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("streaming", __name__) + + +@streaming.route("/stream/<identifier>", methods=["GET"]) +def stream(identifier="output"): + """ This endpoints streams stdout from a file expects + the indetifier to be the file """ + 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 to the last position default to 0 + file_handler.seek(seek_position) + results = {"data": file_handler.readlines(), + "run_id": identifier, + "pointer": file_handler.tell()} + return jsonify(results) |
