Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
northdpole committed Oct 22, 2023
1 parent adfed77 commit 9d0517b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
15 changes: 11 additions & 4 deletions application/database/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -1764,7 +1764,12 @@ def dbCREfromCRE(cre: cre_defs.CRE) -> CRE:
)


def gap_analysis(neo_db:NEO_DB, node_names: List[str],store_in_cache:bool=False, cache_key:str=""):
def gap_analysis(
neo_db: NEO_DB,
node_names: List[str],
store_in_cache: bool = False,
cache_key: str = "",
):
base_standard, paths = neo_db.gap_analysis(node_names[0], node_names[1])
if base_standard is None:
return None
Expand All @@ -1785,13 +1790,15 @@ def gap_analysis(neo_db:NEO_DB, node_names: List[str],store_in_cache:bool=False,
else:
grouped_paths[key]["paths"][end_key] = path

if store_in_cache: # lightweight memory option to not return potentially huge object and instead store in a cache,
if (
store_in_cache
): # lightweight memory option to not return potentially huge object and instead store in a cache,
# in case this is called via worker, we save both this and the caller memory by avoiding duplicate object in mem
conn = redis.from_url(os.getenv("REDIS_URL", "redis://localhost:6379"))
if cache_key == "":
cache_key = make_array_hash(node_names)

conn.set(cache_key,flask_json.dumps({"result":grouped_paths}))
return (node_names,{})
conn.set(cache_key, flask_json.dumps({"result": grouped_paths}))
return (node_names, {})

return (node_names, grouped_paths)
2 changes: 1 addition & 1 deletion application/utils/hash.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import hashlib


def make_array_hash(array: list):
return hashlib.md5(":".join(array).encode("utf-8")).hexdigest()

17 changes: 14 additions & 3 deletions application/web/web_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ def find_document_by_tag() -> Any:
logger.info("tags aborting 404")
abort(404)


@app.route("/rest/v1/map_analysis", methods=["GET"])
@cache.cached(timeout=50, query_string=True)
def gap_analysis() -> Any:
Expand All @@ -236,9 +237,17 @@ def gap_analysis() -> Any:
return jsonify({"job_id": gap_analysis_dict.get("job_id")})

q = Queue(connection=conn)
gap_analysis_job = q.enqueue_call(db.gap_analysis, kwargs={"neo_db":database.neo_db, "node_names": standards,"store_in_cache":True, "cache_key":standards_hash})
gap_analysis_job = q.enqueue_call(
db.gap_analysis,
kwargs={
"neo_db": database.neo_db,
"node_names": standards,
"store_in_cache": True,
"cache_key": standards_hash,
},
)

conn.set(standards_hash, json.dumps({"job_id":gap_analysis_job.id,"result":""}))
conn.set(standards_hash, json.dumps({"job_id": gap_analysis_job.id, "result": ""}))
return jsonify({"job_id": gap_analysis_job.id})


Expand Down Expand Up @@ -287,7 +296,9 @@ def fetch_job() -> Any:
if ga.get("result"):
return jsonify({"result": ga.get("result")})
else:
logger.error("Finished job does not have a result object, this is a bug!")
logger.error(
"Finished job does not have a result object, this is a bug!"
)
abort(500, "this is a bug, please raise a ticket")

elif res.latest_result().type == result.Type.FAILED:
Expand Down

0 comments on commit 9d0517b

Please sign in to comment.