diff options
author | Frederick Muriuki Muriithi | 2024-01-24 12:29:10 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2024-01-24 12:29:10 +0300 |
commit | 07deef46a3f3ba53cc632a9381fb25c55e1017b1 (patch) | |
tree | a2f4fd1c9f9f69ed774ceff7d0cc5549f630bf9e /qc_app/parse.py | |
parent | 96c600723726c3391532d86d17183bea960ece57 (diff) | |
download | gn-uploader-07deef46a3f3ba53cc632a9381fb25c55e1017b1.tar.gz |
Checks: Update code and tests to ensure all checks pass.
Diffstat (limited to 'qc_app/parse.py')
-rw-r--r-- | qc_app/parse.py | 70 |
1 files changed, 35 insertions, 35 deletions
diff --git a/qc_app/parse.py b/qc_app/parse.py index d9be993..f0c53d1 100644 --- a/qc_app/parse.py +++ b/qc_app/parse.py @@ -76,47 +76,47 @@ def parse(): redisurl, f"{app.config['UPLOAD_FOLDER']}/job_errors") - return redirect(url_for("parse.parse_status", job_id=job["job_id"])) + return redirect(url_for("parse.parse_status", job_id=job["jobid"])) @parsebp.route("/status/<job_id>", methods=["GET"]) def parse_status(job_id: str): "Retrieve the status of the job" with Redis.from_url(app.config["REDIS_URL"], decode_responses=True) as rconn: - job = jobs.job(rconn, jobs.jobsnamespace(), job_id) - - if job: - error_filename = jobs.error_filename( - job_id, f"{app.config['UPLOAD_FOLDER']}/job_errors") - if os.path.exists(error_filename): - stat = os.stat(error_filename) - if stat.st_size > 0: - return redirect(url_for("parse.fail", job_id=job_id)) - - job_id = job["job_id"] - progress = float(job["percent"]) - status = job["status"] - filename = job.get("filename", "uploaded file") - errors = jsonpickle.decode( - job.get("errors", jsonpickle.encode(tuple()))) - if status in ("success", "aborted"): - return redirect(url_for("parse.results", job_id=job_id)) - - if status == "parse-error": + try: + job = jobs.job(rconn, jobs.jobsnamespace(), job_id) + except jobs.JobNotFound as _exc: + return render_template("no_such_job.html", job_id=job_id), 400 + + error_filename = jobs.error_filename( + job_id, f"{app.config['UPLOAD_FOLDER']}/job_errors") + if os.path.exists(error_filename): + stat = os.stat(error_filename) + if stat.st_size > 0: return redirect(url_for("parse.fail", job_id=job_id)) - app.jinja_env.globals.update( - isinvalidvalue=isinvalidvalue, - isduplicateheading=isduplicateheading) - return render_template( - "job_progress.html", - job_id = job_id, - job_status = status, - progress = progress, - message = job.get("message", ""), - job_name = f"Parsing '{filename}'", - errors=errors) - - return render_template("no_such_job.html", job_id=job_id), 400 + job_id = job["jobid"] + progress = float(job["percent"]) + status = job["status"] + filename = job.get("filename", "uploaded file") + errors = jsonpickle.decode( + job.get("errors", jsonpickle.encode(tuple()))) + if status in ("success", "aborted"): + return redirect(url_for("parse.results", job_id=job_id)) + + if status == "parse-error": + return redirect(url_for("parse.fail", job_id=job_id)) + + app.jinja_env.globals.update( + isinvalidvalue=isinvalidvalue, + isduplicateheading=isduplicateheading) + return render_template( + "job_progress.html", + job_id = job_id, + job_status = status, + progress = progress, + message = job.get("message", ""), + job_name = f"Parsing '{filename}'", + errors=errors) @parsebp.route("/results/<job_id>", methods=["GET"]) def results(job_id: str): @@ -135,7 +135,7 @@ def results(job_id: str): errors=errors, job_name = f"Parsing '{filename}'", user_aborted = job.get("user_aborted"), - job_id=job["job_id"]) + job_id=job["jobid"]) return render_template("no_such_job.html", job_id=job_id) |