diff options
Diffstat (limited to 'uploader/background_jobs.py')
| -rw-r--r-- | uploader/background_jobs.py | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/uploader/background_jobs.py b/uploader/background_jobs.py index dc9f837..4e1cd13 100644 --- a/uploader/background_jobs.py +++ b/uploader/background_jobs.py @@ -4,10 +4,9 @@ import importlib from typing import Callable from functools import partial +from werkzeug.wrappers.response import Response from flask import ( - url_for, redirect, - Response, Blueprint, render_template, current_app as app) @@ -16,6 +15,10 @@ from gn_libs import jobs from gn_libs import sqlite3 from gn_libs.jobs.jobs import JobNotFound + +from uploader.sui import sui_template + +from uploader.flask_extensions import url_for from uploader.authorisation import require_login background_jobs_bp = Blueprint("background-jobs", __name__) @@ -45,7 +48,7 @@ def register_handlers( return job_type -def register_job_handlers(job: str): +def register_job_handlers(job: dict): """Related to register handlers above.""" def __load_handler__(absolute_function_path): _parts = absolute_function_path.split(".") @@ -56,7 +59,7 @@ def register_job_handlers(job: str): return getattr(module, _parts[-1]) metadata = job["metadata"] - if metadata["success_handler"]: + if metadata.get("success_handler"): _success_handler = __load_handler__(metadata["success_handler"]) try: _error_handler = __load_handler__(metadata["error_handler"]) @@ -76,8 +79,12 @@ def handler(job: dict, handler_type: str) -> HandlerType: ).get(handler_type) if bool(_handler): return _handler(job) - raise Exception(# pylint: disable=[broad-exception-raised] - f"No '{handler_type}' handler registered for job type: {_job_type}") + + def __default_success_handler__(_job): + return render_template( + sui_template("background-jobs/default-success-page.html"), job=_job) + + return __default_success_handler__ error_handler = partial(handler, handler_type="error") @@ -100,10 +107,10 @@ def job_status(job_id: uuid.UUID): if status == "completed": return success_handler(job) - return render_template("jobs/job-status.html", job=job) + return render_template(sui_template("jobs/job-status.html"), job=job) except JobNotFound as _jnf: return render_template( - "jobs/job-not-found.html", + sui_template("jobs/job-not-found.html"), job_id=job_id) @@ -114,6 +121,7 @@ def job_error(job_id: uuid.UUID): with sqlite3.connection(app.config["ASYNCHRONOUS_JOBS_SQLITE_DB"]) as conn: try: job = jobs.job(conn, job_id, fulldetails=True) - return render_template("jobs/job-error.html", job=job) + return render_template(sui_template("jobs/job-error.html"), job=job) except JobNotFound as _jnf: - return render_template("jobs/job-not-found.html", job_id=job_id) + return render_template(sui_template("jobs/job-not-found.html"), + job_id=job_id) |
