diff options
Diffstat (limited to 'gn3/api/async_commands.py')
-rw-r--r-- | gn3/api/async_commands.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/gn3/api/async_commands.py b/gn3/api/async_commands.py new file mode 100644 index 0000000..c0cf4bb --- /dev/null +++ b/gn3/api/async_commands.py @@ -0,0 +1,16 @@ +"""Endpoints and functions concerning commands run in external processes.""" +import redis +from flask import jsonify, Blueprint + +async_commands = Blueprint("async_commands", __name__) + +@async_commands.route("/state/<command_id>") +def command_state(command_id): + """Respond with the current state of command identified by `command_id`.""" + with redis.Redis(decode_responses=True) as rconn: + state = rconn.hgetall(name=command_id) + if not state: + return jsonify( + status=404, + error="The command id provided does not exist.") + return jsonify(dict(state.items())) |