diff options
author | Frederick Muriuki Muriithi | 2025-04-21 13:49:07 -0500 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2025-04-21 13:49:07 -0500 |
commit | 3c948fe68dc4f40f158da92a150a300bd9ca2efb (patch) | |
tree | 2bc051c53674189bf55207915c7f5fecedc442b8 /uploader/background_jobs.py | |
parent | 3dfc86e8fa5d2cdd41dc0df390734ebcaf06d99f (diff) | |
download | gn-uploader-3c948fe68dc4f40f158da92a150a300bd9ca2efb.tar.gz |
Implement rudimentary status update page for background jobs.
Diffstat (limited to 'uploader/background_jobs.py')
-rw-r--r-- | uploader/background_jobs.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/uploader/background_jobs.py b/uploader/background_jobs.py new file mode 100644 index 0000000..ac47ff2 --- /dev/null +++ b/uploader/background_jobs.py @@ -0,0 +1,35 @@ +import uuid + +from flask import request, Blueprint, render_template, current_app as app + +from gn_libs import jobs +from gn_libs.jobs.jobs import JobNotFound +from gn_libs import sqlite3 + +from uploader.authorisation import require_login + +background_jobs_bp = Blueprint("background-jobs", __name__) + +@background_jobs_bp.route("/status/<uuid:job_id>") +@require_login +def job_status(job_id: uuid.UUID): + """View the job status.""" + with sqlite3.connection(app.config["ASYNCHRONOUS_JOBS_SQLITE_DB"]) as conn: + try: + job = jobs.job(conn, job_id, fulldetails=True) + stdout = "" + stderr = "" + # with (open(job["metadata"]["stdout-file"], encoding="utf-8") as stdout_file, + # open(job["metadata"]["stderr-file"], encoding="utf-8") as stderr_file): + # stdout = stdout_file.read() + # stderr = stderr_file.read() + + return render_template( + f"jobs/job-status.html", + job=job, + stdout=stdout, + stderr=stderr) + except JobNotFound as jnf: + return render_template( + "jobs/job-not-found.html", + job_id=job_id) |