aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-04-18 13:57:49 +0300
committerFrederick Muriuki Muriithi2023-04-18 14:10:47 +0300
commit0958648c62452a53d0f66d7401261015e39d2fb8 (patch)
treeeaca4e23b40ab116875378ca1a7965a78a26dac3 /scripts
parent03bbc359b84c000baaf20415ff3ad1f9acca2817 (diff)
downloadgenenetwork3-0958648c62452a53d0f66d7401261015e39d2fb8.tar.gz
auth: Consistently JSON encode values.
Consistently encode all values for the top-level keys stored in redis to avoid issues with json encode/decode
Diffstat (limited to 'scripts')
-rw-r--r--scripts/search_phenotypes.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/scripts/search_phenotypes.py b/scripts/search_phenotypes.py
index 4533cce..7049834 100644
--- a/scripts/search_phenotypes.py
+++ b/scripts/search_phenotypes.py
@@ -44,6 +44,10 @@ def remove_linked(search_results, linked: tuple):
"""Remove any item that has been already linked to a user group."""
return (item for item in search_results if __filter_object__(item) not in linked)
+def update_status(redisconn: redis.Redis, redisname, status: str):
+ """Update the status of the search."""
+ redisconn.hset(redisname, "status", json.dumps(status))
+
def update_search_results(redisconn: redis.Redis, redisname: str,
results: tuple[dict[str, Any], ...]):
"""Save the results to redis db."""
@@ -83,7 +87,7 @@ def search(# pylint: disable=[too-many-arguments, too-many-locals]
with (authdb.connection(auth_db_uri) as authconn,
gn3db.database_connection(gn3_db_uri) as gn3conn,
redis.Redis.from_url(redis_uri, decode_responses=True) as redisconn):
- redisconn.hset(redisname, "status", "started")
+ update_status(redisconn, redisname, "started")
update_search_results(redisconn, redisname, tuple()) # init search results
try:
search_query = f"species:{species}" + (
@@ -109,11 +113,11 @@ def search(# pylint: disable=[too-many-arguments, too-many-locals]
except NoSearchResults as _nsr:
pass
except Exception as _exc: # pylint: disable=[broad-except]
- redisconn.hset(redisname, "status", "failed")
- redisconn.hset(redisname, "exception", traceback.format_exc())
+ update_status(redisconn, redisname, "failed")
+ redisconn.hset(redisname, "exception", json.dumps(traceback.format_exc()))
expire_redis_results(redisconn, redisname)
return 1
- redisconn.hset(redisname, "status", "completed")
+ update_status(redisconn, redisname, "completed")
expire_redis_results(redisconn, redisname)
return 0