From f875926183e2e26881c3288e2f5c3d8ffe6397b8 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Mon, 22 Jan 2024 08:54:29 +0300 Subject: UI: Show progress of R/qtl2 bundle processing. --- qc_app/templates/rqtl2/no-such-job.html | 13 +++++++++++ qc_app/templates/rqtl2/rqtl2-job-error.html | 33 +++++++++++++++++++++++++++ qc_app/templates/rqtl2/rqtl2-job-results.html | 24 +++++++++++++++++++ qc_app/templates/rqtl2/rqtl2-job-status.html | 24 +++++++++++++++++++ qc_app/upload/rqtl2.py | 26 +++++++++++++++++++-- scripts/process_rqtl2_bundle.py | 1 - scripts/worker.py | 6 ++++- 7 files changed, 123 insertions(+), 4 deletions(-) create mode 100644 qc_app/templates/rqtl2/no-such-job.html create mode 100644 qc_app/templates/rqtl2/rqtl2-job-error.html create mode 100644 qc_app/templates/rqtl2/rqtl2-job-results.html create mode 100644 qc_app/templates/rqtl2/rqtl2-job-status.html diff --git a/qc_app/templates/rqtl2/no-such-job.html b/qc_app/templates/rqtl2/no-such-job.html new file mode 100644 index 0000000..b56980b --- /dev/null +++ b/qc_app/templates/rqtl2/no-such-job.html @@ -0,0 +1,13 @@ +{%extends "base.html"%} +{%from "flash_messages.html" import flash_messages%} + +{%block title%}Job Status{%endblock%} + +{%block contents%} +

R/qtl2 job status

+ +

R/qtl2 Upload: No Such Job

+ +

No job with ID {{jobid}} was found.

+ +{%endblock%} diff --git a/qc_app/templates/rqtl2/rqtl2-job-error.html b/qc_app/templates/rqtl2/rqtl2-job-error.html new file mode 100644 index 0000000..72a334b --- /dev/null +++ b/qc_app/templates/rqtl2/rqtl2-job-error.html @@ -0,0 +1,33 @@ +{%extends "base.html"%} +{%from "cli-output.html" import cli_output%} + +{%block title%}Job Status{%endblock%} + +{%block contents%} +

R/qtl2 job status

+ +

R/qtl2 Upload: Job Status

+ +
+

The processing of the R/qtl2 bundle you uploaded has failed. We have + provided some information below to help you figure out what the problem + could be.

+

If you find that you cannot figure out what the problem is on your own, + please contact the team running the system for assistance, providing the + R/qtl2 bundle you uploaded, and a screenshot of this page.

+
+ +

stdout

+{{cli_output(job, "stdout")}} + +

stderr

+{{cli_output(job, "stderr")}} + +

Log

+
+ {%for msg in messages%} + {{msg}}
+ {%endfor%} +
+ +{%endblock%} diff --git a/qc_app/templates/rqtl2/rqtl2-job-results.html b/qc_app/templates/rqtl2/rqtl2-job-results.html new file mode 100644 index 0000000..4ecd415 --- /dev/null +++ b/qc_app/templates/rqtl2/rqtl2-job-results.html @@ -0,0 +1,24 @@ +{%extends "base.html"%} +{%from "cli-output.html" import cli_output%} + +{%block title%}Job Status{%endblock%} + +{%block contents%} +

R/qtl2 job status

+ +

R/qtl2 Upload: Job Status

+ +
+

The processing of the R/qtl2 bundle you uploaded has completed + successfully.

+

You should now be able to use GeneNetwork to run analyses on your data.

+
+ +

Log

+
+ {%for msg in messages%} + {{msg}}
+ {%endfor%} +
+ +{%endblock%} diff --git a/qc_app/templates/rqtl2/rqtl2-job-status.html b/qc_app/templates/rqtl2/rqtl2-job-status.html new file mode 100644 index 0000000..a8bc640 --- /dev/null +++ b/qc_app/templates/rqtl2/rqtl2-job-status.html @@ -0,0 +1,24 @@ +{%extends "base.html"%} +{%from "flash_messages.html" import flash_messages%} + +{%block title%}Job Status{%endblock%} + +{%block extrameta%} + +{%endblock%} + +{%block contents%} +

R/qtl2 job status

+ +

R/qtl2 Upload: Job Status

+ +{{job}} + +

Log

+
+ {%for msg in messages%} + {{msg}}
+ {%endfor%} +
+ +{%endblock%} diff --git a/qc_app/upload/rqtl2.py b/qc_app/upload/rqtl2.py index 7ba90c2..8a0d8b4 100644 --- a/qc_app/upload/rqtl2.py +++ b/qc_app/upload/rqtl2.py @@ -1,9 +1,9 @@ """Module to handle uploading of R/qtl2 bundles.""" import sys import json -from uuid import uuid4 from pathlib import Path from datetime import date +from uuid import UUID, uuid4 from zipfile import ZipFile, is_zipfile from redis import Redis @@ -581,4 +581,26 @@ def confirm_bundle_details(species_id: int, population_id: int): redisuri, f"{app.config['UPLOAD_FOLDER']}/job_errors") - raise NotImplementedError + return redirect(url_for("upload.rqtl2.rqtl2_processing_status", + jobid=jobid)) + +@rqtl2.route("/status/") +def rqtl2_processing_status(jobid: UUID): + """Retrieve the status of the job processing the uploaded R/qtl2 bundle.""" + with Redis.from_url(app.config["REDIS_URL"], decode_responses=True) as rconn: + thejob = jobs.job(rconn, jobid) + if not bool(thejob): + return render_template("rqtl2/no-such-job.html", jobid=jobid) + + logmessages = rconn.lrange(thejob.get("log-messagelist"), 0, -1) or [] + + if thejob["status"] == "error": + return render_template( + "rqtl2/rqtl2-job-error.html", job=thejob, messages=logmessages) + if thejob["status"] == "success": + return render_template("rqtl2/rqtl2-job-results.html", + job=thejob, + messages=logmessages) + + return render_template( + "rqtl2/rqtl2-job-status.html", job=thejob, messages=logmessages) diff --git a/scripts/process_rqtl2_bundle.py b/scripts/process_rqtl2_bundle.py index 105f787..feb5e19 100644 --- a/scripts/process_rqtl2_bundle.py +++ b/scripts/process_rqtl2_bundle.py @@ -59,7 +59,6 @@ def process_bundle(dbconn: mdb.Connection, rconn: Redis, jobid: uuid.UUID) -> in try: thejob = parse_job(rconn, jobid) meta = thejob["bundle-metadata"] - logger.debug("The metadata: %s", meta) rconn.hset(str(jobid), "geno-percent", "0") rconn.hset(str(jobid), "pheno-percent", "0") diff --git a/scripts/worker.py b/scripts/worker.py index 13556df..90d83c4 100644 --- a/scripts/worker.py +++ b/scripts/worker.py @@ -54,10 +54,14 @@ def run_job(job, rconn): rconn, job_id, process.stdout.read1(), "stdout") sleep(1) + update_status( + rconn, + job_id, + ("error" if process.returncode != 0 else "success")) + with open(stderrpath, "rb") as stderr: stderr_content = stderr.read() update_stdout_stderr(rconn, job_id, stderr_content, "stderr") - update_status(rconn, job_id, ("error" if bool(stderr_content) else "success")) os.remove(stderrpath) return process.poll() -- cgit v1.2.3