aboutsummaryrefslogtreecommitdiff
path: root/qc_app/dbinsert.py
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2022-08-04 08:51:15 +0300
committerFrederick Muriuki Muriithi2022-08-04 08:51:15 +0300
commit3da6848381b6103fbb58eeab8d7051cba0bded58 (patch)
treefd20aa2d8c73638b72a7667504582f0146aa182f /qc_app/dbinsert.py
parent7bd9116019afe4aed369c5dfe69496abc6867381 (diff)
downloadgn-uploader-3da6848381b6103fbb58eeab8d7051cba0bded58.tar.gz
Implement data insertion
- Hook up external data insertion script to webserver code - Provide rudimentary status indication - Generalise some job creation details
Diffstat (limited to 'qc_app/dbinsert.py')
-rw-r--r--qc_app/dbinsert.py43
1 files changed, 42 insertions, 1 deletions
diff --git a/qc_app/dbinsert.py b/qc_app/dbinsert.py
index 0b87c20..70aeb6d 100644
--- a/qc_app/dbinsert.py
+++ b/qc_app/dbinsert.py
@@ -5,7 +5,6 @@ from typing import Union
from functools import reduce
from datetime import datetime
-import requests
from redis import Redis
from MySQLdb.cursors import DictCursor
from flask import (
@@ -359,3 +358,45 @@ def final_confirmation():
"DataScale")))
except AssertionError as aserr:
return render_error(f"Missing data: {aserr.args[0]}")
+
+@dbinsertbp.route("/insert-data", methods=["POST"])
+def insert_data():
+ "Trigger data insertion"
+ form = request.form
+ try:
+ assert form.get("filename"), "filename"
+ assert form.get("filetype"), "filetype"
+ assert form.get("species"), "species"
+ assert form.get("genechipid"), "platform"
+ assert form.get("studyid"), "study"
+ assert form.get("datasetid"), "dataset"
+
+ filename = form["filename"]
+ filepath = f"{app.config['UPLOAD_FOLDER']}/{filename}"
+ redisurl = app.config["REDIS_URL"]
+ if os.path.exists(filepath):
+ with Redis.from_url(redisurl, decode_responses=True) as rconn:
+ job = jobs.launch_job(
+ jobs.data_insertion_job(
+ rconn, filepath, form.get("filetype"),
+ form.get("species"), form.get("genechipid"),
+ form.get("datasetid"), app.config["SQL_URI"], redisurl,
+ app.config["JOBS_TTL_SECONDS"]),
+ redisurl, f"{app.config['UPLOAD_FOLDER']}/job_errors")
+
+ return redirect(url_for("dbinsert.insert_status", job_id=job["job_id"]))
+ return render_error(f"File '{filename}' no longer exists.")
+ except AssertionError as aserr:
+ return render_error(f"Missing data: {aserr.args[0]}")
+
+@dbinsertbp.route("/status/<job_id>", methods=["GET"])
+def insert_status(job_id: str):
+ "Retrieve status of data insertion."
+ with Redis.from_url(app.config["REDIS_URL"], decode_responses=True) as rconn:
+ job = jobs.job(rconn, job_id)
+
+ if job:
+ if job["status"] == "success":
+ return render_template("insert_success.html", job=job)
+ return render_template("insert_progress.html", job=job)
+ return render_template("no_such_job.html", job_id=job_id), 400