diff options
Diffstat (limited to 'uploader/phenotypes/views.py')
-rw-r--r-- | uploader/phenotypes/views.py | 67 |
1 files changed, 57 insertions, 10 deletions
diff --git a/uploader/phenotypes/views.py b/uploader/phenotypes/views.py index 49c12b5..6bc7471 100644 --- a/uploader/phenotypes/views.py +++ b/uploader/phenotypes/views.py @@ -23,6 +23,7 @@ from werkzeug.utils import secure_filename from gn_libs import sqlite3 from gn_libs import jobs as gnlibs_jobs +from gn_libs.jobs.jobs import JobNotFound from gn_libs.mysqldb import database_connection from gn_libs import monadic_requests as mrequests @@ -613,6 +614,16 @@ def review_job_data( activelink="add-phenotypes") +def load_phenotypes_success_handler(job): + """Handle loading new phenotypes into the database successfully.""" + return redirect(url_for( + "species.populations.phenotypes.load_data_success", + species_id=job["metadata"]["species_id"], + population_id=job["metadata"]["population_id"], + dataset_id=job["metadata"]["dataset_id"], + job_id=job["job_id"])) + + @phenotypesbp.route( "<int:species_id>/populations/<int:population_id>/phenotypes/datasets" "/<int:dataset_id>/load-data-to-database", @@ -635,6 +646,7 @@ def load_data_to_database( qc_job = jobs.job(rconn, jobs.jobsnamespace(), request.form["data-qc-job-id"]) _meta = json.loads(qc_job["job-metadata"]) load_job_id = uuid.uuid4() + _loglevel = logging.getLevelName(app.logger.getEffectiveLevel()).lower() command = [ sys.executable, "-u", @@ -644,17 +656,17 @@ def load_data_to_database( jobs_db, str(load_job_id), "--log-level", - logging.getLevelName( - app.logger.getEffectiveLevel() - ).lower() + _loglevel ] def __handle_error__(resp): - raise Exception(resp) + return render_template("http-error.html", *resp.json()) def __handle_success__(load_job): app.logger.debug("The phenotypes loading job: %s", load_job) - return str(load_job) + return redirect(url_for( + "background-jobs.job_status", job_id=load_job["job_id"])) + issued = datetime.datetime.now() jwtkey = jwks.newest_jwk_with_rotation( jwks.jwks_directory(app, "UPLOADER_SECRETS"), @@ -697,15 +709,20 @@ def load_data_to_database( "population_id": population["Id"], "dataset_id": dataset["Id"], "bundle_file": _meta["bundle"], + "publication_id": _meta["publicationid"], "authserver": oauth2client.authserver_uri(), - "token": token["access_token"] + "token": token["access_token"], + "success_handler": ( + "uploader.phenotypes.views" + ".load_phenotypes_success_handler") }) ).then( lambda job: gnlibs_jobs.launch_job( - job, - jobs_db, - f"{app.config['UPLOAD_FOLDER']}/job_errors", - worker_manager="gn_libs.jobs.launcher") + job, + jobs_db, + f"{app.config['UPLOAD_FOLDER']}/job_errors", + worker_manager="gn_libs.jobs.launcher", + loglevel=_loglevel) ).either(__handle_error__, __handle_success__) @@ -1114,3 +1131,33 @@ def edit_upload_phenotype_data(# pylint: disable=[unused-argument] return redirect(url_for("background-jobs.job_status", job_id=job_id, job_type="phenotype-bulk-edit")) + + +@phenotypesbp.route( + "<int:species_id>/populations/<int:population_id>/phenotypes/datasets" + "/<int:dataset_id>/load-data-success/<uuid:job_id>", + methods=["GET"]) +@require_login +@with_dataset( + species_redirect_uri="species.populations.phenotypes.index", + population_redirect_uri="species.populations.phenotypes.select_population", + redirect_uri="species.populations.phenotypes.list_datasets") +def load_data_success( + species: dict, + population: dict, + dataset: dict, + job_id: uuid.UUID, + **kwargs +):# pylint: disable=[unused-argument] + with sqlite3.connection(app.config["ASYNCHRONOUS_JOBS_SQLITE_DB"]) as conn: + try: + job = gnlibs_jobs.job(conn, job_id, fulldetails=True) + app.logger.debug("THE JOB: %s", job) + return render_template("phenotypes/load-phenotypes-success.html", + species=species, + population=population, + dataset=dataset, + job=job, + gn2_server_url=app.config["GN2_SERVER_URL"]) + except JobNotFound as jnf: + return render_template("jobs/job-not-found.html", job_id=job_id) |