aboutsummaryrefslogtreecommitdiff
path: root/gn3/jobs.py
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 /gn3/jobs.py
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 'gn3/jobs.py')
-rw-r--r--gn3/jobs.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/gn3/jobs.py b/gn3/jobs.py
index 8854a61..1af63f7 100644
--- a/gn3/jobs.py
+++ b/gn3/jobs.py
@@ -5,9 +5,10 @@ from uuid import UUID, uuid4
from datetime import datetime
from redis import Redis
-
from pymonad.either import Left, Right, Either
+from gn3 import json_encoders_decoders as jed
+
JOBS_NAMESPACE = "GN3::JOBS"
class InvalidCommand(Exception):
@@ -22,8 +23,8 @@ def job(redisconn: Redis, job_id: UUID) -> Either:
the_job = redisconn.hgetall(job_key(job_id))
if the_job:
return Right({
- **the_job,
- "search_results": json.loads(the_job["search_results"])
+ key: json.loads(value, object_hook=jed.custom_json_decoder)
+ for key, value in the_job.items()
})
return Left({
"error": "NotFound",
@@ -48,8 +49,10 @@ def create_job(redisconn: Redis, job_details: dict[str, Any]) -> UUID:
def __create__(_job_command):
job_id = job_details.get("job_id", uuid4())
redisconn.hset(job_key(job_id), mapping={
- **job_details, "job_id": job_id, "created": datetime.now(), "stdout": "",
- "stderr": "", "status": "queued"
+ key: json.dumps(value, cls=jed.CustomJSONEncoder) for key, value in {
+ **job_details, "job_id": job_id, "created": datetime.now(),
+ "status": "queued"
+ }.items()
})
return job_id
def __raise__(err):