Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"pandda_xchem = dlstbx.wrapper.pandda_xchem:PanDDAWrapper",
"pipedream_xchem = dlstbx.wrapper.pipedream_xchem:PipedreamWrapper",
"phaser_ellg = dlstbx.wrapper.phaser_ellg:PhasereLLGWrapper",
"ligandrestraints = dlstbx.wrapper.ligandrestraints:LigandRestraintsWrapper",
"rlv = dlstbx.wrapper.rlv:RLVWrapper",
"scaleit = dlstbx.wrapper.scaleit:ScaleitWrapper",
"screen19 = dlstbx.wrapper.screen19:Screen19Wrapper",
Expand Down
18 changes: 18 additions & 0 deletions src/dlstbx/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,24 @@ def get_data_collection(
return query.first()


def get_latest_dcid_for_dtag(
dtag: str,
session: sqlalchemy.orm.session.Session,
) -> int | None:
"""Return the most recent dataCollectionId for the BLSample named `dtag`."""
query = (
session.query(models.DataCollection.dataCollectionId)
.join(
models.BLSample,
models.BLSample.blSampleId == models.DataCollection.BLSAMPLEID,
)
.filter(models.BLSample.name == dtag)
.order_by(models.DataCollection.dataCollectionId.desc())
)
result = query.first()
return result.dataCollectionId if result else None


def get_gridinfo_for_dcid(
dcid: int,
dcgid: int,
Expand Down
73 changes: 72 additions & 1 deletion src/dlstbx/services/ispybsvc.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@
import pydantic
import sqlalchemy.orm
import workflows.recipe
from ispyb.sqlalchemy import PDB, ProteinHasPDB
from ispyb.sqlalchemy import (
PDB,
BLSession,
Person,
Proposal,
ProteinHasPDB,
SessionHasPerson,
)
from workflows.services.common_service import CommonService

import dlstbx.services.ispybsvc_buffer as buffer
Expand Down Expand Up @@ -1016,6 +1023,70 @@ def do_retrieve_proposal_title(self, parameters, **kwargs):
)
return False

def do_notify_visit_team_leader(
self,
parameters,
session: sqlalchemy.orm.Session,
rw,
transaction,
**kwargs,
):
"""Email the visit's Team Leader that XChemCollate has finished.

Looks up the Team Leader for the given visit in ISPyB and sends a simple
notification to the mailnotification queue (consumed by the DLS Mail
Notifications / zocalo Mailer service)."""

visit = parameters("visit")
results_directory = parameters("results_directory")

# recipients = self._lookup_visit_team_leader_emails(session, visit)
# if not recipients:
# self.log.warning(
# "No Team Leader found for visit %s; skipping collate-finished email",
# visit,
# )
# return {"success": True}
recipients = ["qvu59474@diamond.ac.uk"]

message = {
"parameters": {
"recipients": recipients,
"subject": f"Auto pipeline finished for {visit}",
},
"content": [
f"Beamline visit processing has now finished for {visit}.\n",
f"Results are available at {results_directory}",
],
}
self.log.info("Sending collate-finished email to %r", recipients)
rw.transport.send("mailnotification", message, transaction=transaction)
return {"success": True}

def _lookup_visit_team_leader_emails(self, session, visit):
"""Return ``<login>@diamond.ac.uk`` for the Team Leader(s) of a visit."""
try:
proposal, visit_number = visit.split("-")
proposal_code, proposal_number = proposal[:2], proposal[2:]
except (AttributeError, ValueError):
self.log.error("Could not parse visit %r for team leader lookup", visit)
return []

logins = (
session.query(Person.login)
.join(SessionHasPerson, SessionHasPerson.personId == Person.personId)
.join(BLSession, BLSession.sessionId == SessionHasPerson.sessionId)
.join(Proposal, Proposal.proposalId == BLSession.proposalId)
.filter(
Proposal.proposalCode == proposal_code,
Proposal.proposalNumber == proposal_number,
BLSession.visit_number == visit_number,
SessionHasPerson.role == "Team Leader",
)
.all()
)
return [f"{login}@diamond.ac.uk" for (login,) in logins if login]

def do_insert_phasing_analysis_results(self, parameters, **kwargs):
"""Write phasing results to ISPyB"""

Expand Down
Loading