Skip to content

Commit

Permalink
Fixed display of proposal in case ISPyB is not available
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Gruzinov committed Sep 13, 2024
1 parent f3478d1 commit 957112c
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions mxcubecore/HardwareObjects/DESY/P11ISPyBClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
import ssl
from mxcubecore.HardwareObjects.ISPyBClient import ISPyBClient
from mxcubecore import HardwareRepository as HWR
from suds import WebFault
from urllib.error import URLError
from suds.transport import TransportError


ssl._create_default_https_context = ssl._create_unverified_context

Expand Down Expand Up @@ -73,3 +77,36 @@ def prepare_image_for_lims(self, image_dict):
image_dict[prop] = ispyb_path
except RuntimeWarning("Can not prepare image path fir LIMS for %s" % prop):
pass

def get_proposal(self, proposal_code, proposal_number):
logging.getLogger("HWR").debug(
"ISPyB. Obtaining proposal for code=%s / prop_number=%s"
% (proposal_code, proposal_number)
)

try:
if self._shipping:
# Attempt to fetch the proposal from ISPyB
proposal = self._shipping.service.findProposal(
proposal_code, proposal_number
)
else:
raise URLError("Shipping service unavailable")

if proposal:
proposal["code"] = proposal_code
proposal["number"] = proposal_number
return {"Proposal": proposal, "status": {"code": "ok"}}
except (WebFault, URLError, TransportError) as e:
# Log the error and fallback
logging.getLogger("ispyb_client").exception(
"Error fetching proposal. Returning fallback values."
)
return {
"Proposal": {
"code": proposal_code,
"number": proposal_number,
"title": "Unknown Proposal",
},
"status": {"code": "error", "msg": "ISPyB is not connected."},
}

0 comments on commit 957112c

Please sign in to comment.