aboutsummaryrefslogtreecommitdiff
path: root/uploader/background_jobs.py
blob: ac47ff2c95eb0e08dd0ea792de8a84e402b2cada (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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)