aboutsummaryrefslogtreecommitdiff
path: root/gn2/wqflask/api/jobs.py
diff options
context:
space:
mode:
authorAlexander_Kabui2024-01-02 13:21:07 +0300
committerAlexander_Kabui2024-01-02 13:21:07 +0300
commit70c4201b332e0e2c0d958428086512f291469b87 (patch)
treeaea4fac8782c110fc233c589c3f0f7bd34bada6c /gn2/wqflask/api/jobs.py
parent5092eb42f062b1695c4e39619f0bd74a876cfac2 (diff)
parent965ce5114d585624d5edb082c710b83d83a3be40 (diff)
downloadgenenetwork2-70c4201b332e0e2c0d958428086512f291469b87.tar.gz
merge changes
Diffstat (limited to 'gn2/wqflask/api/jobs.py')
-rw-r--r--gn2/wqflask/api/jobs.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/gn2/wqflask/api/jobs.py b/gn2/wqflask/api/jobs.py
new file mode 100644
index 00000000..7a948e1a
--- /dev/null
+++ b/gn2/wqflask/api/jobs.py
@@ -0,0 +1,54 @@
+import uuid
+from datetime import datetime
+
+from redis import Redis
+from pymonad.io import IO
+from flask import Blueprint, render_template
+
+from gn2.jobs.jobs import job
+
+jobs = Blueprint("jobs", __name__)
+
+@jobs.route("/debug/<uuid:job_id>")
+def debug_job(job_id: uuid.UUID):
+ """Display job data to assist in debugging."""
+ from gn2.utility.tools import REDIS_URL # Avoids circular import error
+
+ def __stream_to_lines__(stream):
+ removables = (
+ "Set global log level to", "runserver.py: ******",
+ "APPLICATION_ROOT:", "DB_", "DEBUG:", "ELASTICSEARCH_", "ENV:",
+ "EXPLAIN_TEMPLATE_LOADING:", "GEMMA_", "GENENETWORK_FILES",
+ "GITHUB_", "GN2_", "GN3_", "GN_", "HOME:", "JSONIFY_", "JS_",
+ "JSON_", "LOG_", "MAX_", "ORCID_", "PERMANENT_", "PLINK_",
+ "PREFERRED_URL_SCHEME", "PRESERVE_CONTEXT_ON_EXCEPTION",
+ "PROPAGATE_EXCEPTIONS", "REAPER_COMMAND", "REDIS_URL", "SECRET_",
+ "SECURITY_", "SEND_FILE_MAX_AGE_DEFAULT", "SERVER_", "SESSION_",
+ "SMTP_", "SQL_", "TEMPLATES_", "TESTING:", "TMPDIR", "TRAP_",
+ "USE_", "WEBSERVER_")
+ return tuple(filter(
+ lambda line: not any(line.startswith(item) for item in removables),
+ stream.split("\n")))
+
+ def __fmt_datetime(val):
+ return datetime.strptime(val, "%Y-%m-%dT%H:%M:%S.%f").strftime(
+ "%A, %d %B %Y at %H:%M:%S.%f")
+
+ def __render_debug_page__(job):
+ job_details = {key.replace("-", "_"): val for key,val in job.items()}
+ return render_template(
+ "jobs/debug.html",
+ **{
+ **job_details,
+ "request_received_time": __fmt_datetime(
+ job_details["request_received_time"]),
+ "stderr": __stream_to_lines__(job_details["stderr"]),
+ "stdout": __stream_to_lines__(job_details["stdout"])
+ })
+
+ with Redis.from_url(REDIS_URL, decode_responses=True) as rconn:
+ the_job = job(rconn, job_id)
+
+ return the_job.maybe(
+ render_template("jobs/no-such-job.html", job_id=job_id),
+ lambda job: __render_debug_page__(job))