diff options
-rw-r--r-- | gn3/api/async_commands.py | 21 | ||||
-rw-r--r-- | gn3/app.py | 2 |
2 files changed, 23 insertions, 0 deletions
diff --git a/gn3/api/async_commands.py b/gn3/api/async_commands.py new file mode 100644 index 0000000..f8400c8 --- /dev/null +++ b/gn3/api/async_commands.py @@ -0,0 +1,21 @@ +"""Endpoints and functions concerning commands run in external processes.""" +import json + +import redis +from flask import jsonify, Blueprint + +async_commands = Blueprint("async_commands", __name__) + +@async_commands.route("/state/<command_id>") +def command_state(command_id): + with redis.Redis() as rconn: + state = rconn.hgetall(name=command_id) + if not state: + return jsonify( + status=404, + error="The command id provided does not exist.") + state = { + key.decode("utf-8"): val.decode("utf8") + for key,val in state.items() + } + return jsonify(state) @@ -15,6 +15,7 @@ from gn3.api.correlation import correlation from gn3.api.data_entry import data_entry from gn3.api.wgcna import wgcna from gn3.api.ctl import ctl +from gn3.api.async_commands import async_commands def create_app(config: Union[Dict, str, None] = None) -> Flask: """Create a new flask object""" @@ -47,4 +48,5 @@ def create_app(config: Union[Dict, str, None] = None) -> Flask: app.register_blueprint(data_entry, url_prefix="/api/dataentry") app.register_blueprint(wgcna, url_prefix="/api/wgcna") app.register_blueprint(ctl, url_prefix="/api/ctl") + app.register_blueprint(async_commands, url_prefix="/api/async_commands") return app |