diff options
author | Frederick Muriuki Muriithi | 2022-03-03 10:10:12 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2022-03-03 10:20:04 +0300 |
commit | 84fcbdbafdf58d0f1963c69bad5b6bcb9c805ce1 (patch) | |
tree | d5f453322b281466cbb0cbede7d6f6b3d4761452 /gn3/api/async_commands.py | |
parent | 7de9fea87dc2c9bcb242fd7ffda11af63dbf4268 (diff) | |
download | genenetwork3-84fcbdbafdf58d0f1963c69bad5b6bcb9c805ce1.tar.gz |
Add endpoint for checking state of external processes
Long-running computations are handed off to external processes. This avoids
timeouts in the webserver, and also reduces chances of instability of the
webserver.
The results of these long-running computations are needed eventually, so this
commit provides a way to check for the state of the computation, and the
results if any.
Diffstat (limited to 'gn3/api/async_commands.py')
-rw-r--r-- | gn3/api/async_commands.py | 21 |
1 files changed, 21 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) |