Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions LIMS2DB/classes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import copy
import http.client as http_client
import re
from datetime import datetime

Expand All @@ -14,6 +13,7 @@
ReagentType,
Researcher,
)
from ibm_cloud_sdk_core.api_exception import ApiException
from requests import get as rget
from sqlalchemy import text
from sqlalchemy.orm.exc import MultipleResultsFound, NoResultFound
Expand Down Expand Up @@ -452,14 +452,19 @@ def save(self, update_modification_time=True):
doc = None
# When running for a single project, sometimes the connection is lost so retry
try:
self.couch["projects"]
except http_client.BadStatusLine:
self.couch.get_server_information().get_result()
except ApiException:
self.log.warning(f"Access to couch failed before trying to save new doc for project {self.pid}")
pass
db = self.couch["projects"]
view = db.view("project/project_id")
for row in view[self.pid]:
doc = db.get(row.id)
result = self.couch.post_view(
db="projects",
ddoc="project",
view="project_id",
key=self.pid,
include_docs=True,
).get_result()["rows"]
if result:
doc = result[0]["doc"]
if doc:
fields_saved = [
"_id",
Expand Down Expand Up @@ -502,7 +507,11 @@ def save(self, update_modification_time=True):
self.obj["order_details"] = doc["order_details"]

self.log.info(f"Trying to save new doc for project {self.pid}")
db.save(self.obj)
self.couch.put_document(
db="projects",
doc_id=self.obj["_id"],
document=self.obj,
).get_result()
if self.obj.get("details", {}).get("type", "") == "Application":
lib_method_text = f"Library method: {self.obj['details'].get('library_construction_method', 'N/A')}"
application = self.obj.get("details", {}).get("application", "")
Expand Down Expand Up @@ -537,7 +546,10 @@ def save(self, update_modification_time=True):
self.obj["creation_time"] = datetime.now().isoformat()
self.obj["modification_time"] = self.obj["creation_time"]
self.log.info(f"Trying to save new doc for project {self.pid}")
db.save(self.obj)
self.couch.post_document(
db="projects",
document=self.obj,
).get_result()
if self.obj.get("details", {}).get("type", "") == "Application":
genstat_url = f"{self.genstat_proj_url}{self.obj['project_id']}"
lib_method_text = f"Library method: {self.obj['details'].get('library_construction_method', 'N/A')}"
Expand Down
33 changes: 17 additions & 16 deletions LIMS2DB/diff.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
import http.client as http_client

from genologics_sql.utils import get_configuration, get_session
from ibm_cloud_sdk_core.api_exception import ApiException

from LIMS2DB.utils import setupLog


def diff_project_objects(pj_id, couch, proj_db, logfile, oconf):
def diff_project_objects(pj_id, couch, logfile, oconf):
# Import is put here to defer circular imports
from LIMS2DB.classes import ProjectSQL

log = setupLog(f"diff - {pj_id}", logfile)

view = proj_db.view("projects/lims_followed")

def fetch_project(pj_id):
try:
old_project_couchid = view[pj_id].rows[0].value
except (KeyError, IndexError):
log.error(f"No such project {pj_id}")
result = couch.post_view(
db="projects",
ddoc="projects",
view="lims_followed",
key=pj_id,
include_docs=True,
).get_result()["rows"]
if not result:
log.error(f"No project found in couch for {pj_id}")
return None
return old_project_couchid
return result[0]["doc"]

try:
old_project_couchid = fetch_project(pj_id)
except http_client.BadStatusLine:
log.error("BadStatusLine received after large project")
old_project = fetch_project(pj_id)
except ApiException:
log.error("Connection issues after large project")
# Retry
old_project_couchid = fetch_project(pj_id)
old_project = fetch_project(pj_id)

if old_project_couchid is None:
if old_project is None:
return None

old_project = proj_db.get(old_project_couchid)
old_project.pop("_id", None)
old_project.pop("_rev", None)
old_project.pop("modification_time", None)
Expand Down
12 changes: 7 additions & 5 deletions LIMS2DB/flowcell_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,10 @@ def upload_to_couch(couch, runid, lims_data, pro):
elif pc_cg.SEQUENCING.get(str(pro.typeid), "") in ["AVITI Run v1.0"]:
dbname = "element_runs"

db = couch[dbname]
view = db.view("info/id")
doc = None
for row in view[runid]:
doc = db.get(row.value)
result = couch.post_view(db=dbname, ddoc="info", view="id", key=runid, include_docs=True).get_result()["rows"]
if result:
doc = result[0]["doc"]

if doc:
running_notes = {}
Expand All @@ -89,4 +88,7 @@ def upload_to_couch(couch, runid, lims_data, pro):
doc["lims_data"] = lims_data
if running_notes:
doc["lims_data"]["container_running_notes"] = running_notes
db.save(doc)
couch.post_document(
db=dbname,
document=doc,
).get_result()
Loading