From 8243ec56ec9eb26937da4f53d3bbab92541a6a7a Mon Sep 17 00:00:00 2001 From: Steven Serrata Date: Fri, 3 Apr 2020 10:57:40 -0500 Subject: [PATCH] Reduce number of times json() property is called, fixes #148 --- pan_cortex_data_lake/query.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pan_cortex_data_lake/query.py b/pan_cortex_data_lake/query.py index 140399e..f9d2259 100644 --- a/pan_cortex_data_lake/query.py +++ b/pan_cortex_data_lake/query.py @@ -242,22 +242,23 @@ def iter_job_results( ) if not r.ok: raise HTTPError("%s" % r.text) - if r.json()["state"] == "DONE": - page_cursor = r.json()["page"].get("pageCursor") + r_json = r.json() + if r_json["state"] == "DONE": + page_cursor = r_json["page"].get("pageCursor") if page_cursor is not None: params["pageCursor"] = page_cursor yield r else: yield r break - elif r.json()["state"] in ("RUNNING", "PENDING"): + elif r_json["state"] in ("RUNNING", "PENDING"): yield r time.sleep(1) - elif r.json()["state"] == "FAILED": + elif r_json["state"] == "FAILED": yield r break else: - raise CortexError("Bad state: %s" % r.json()["state"]) + raise CortexError("Bad state: %s" % r_json["state"]) def list_jobs( self,