Skip to content

Commit 5ec35bb

Browse files
committed
Add functionality to notify PATo that an email should be sent
The email body is a little sparse at the moment but we're trying to avoid recording too much information in the database
1 parent cb61821 commit 5ec35bb

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/murfey/util/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ class MachineConfig(BaseModel, extra=Extra.allow): # type: ignore
7070
security_configuration_path: Optional[Path] = None
7171
auth_url: str = ""
7272

73+
notifications_queue: str = "pato_notifications"
74+
7375

7476
def from_file(config_file_path: Path, instrument: str = "") -> Dict[str, MachineConfig]:
7577
with open(config_file_path, "r") as config_stream:

src/murfey/workflows/spa/picking.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,24 @@ def _register_picked_particles_use_boxsize(message: dict, _db: Session):
320320
_db.close()
321321

322322

323-
def _request_email(failed_params: List[str]) -> None:
323+
def _request_email(
324+
failed_params: List[str], session_id: int, murfey_db: Session
325+
) -> None:
326+
session = murfey_db.exec(
327+
select(MurfeySession).where(MurfeySession.id == session_id)
328+
).one()
329+
config = get_machine_config(instrument_name=session.instrument_name)[
330+
session.instrument_name
331+
]
332+
if _transport_object:
333+
_transport_object.send(
334+
config.notifications_queue,
335+
{
336+
"session": session.visit,
337+
"message": f"The following parameters consistently exceeded the user set bounds: {failed_params}",
338+
},
339+
new_connection=True,
340+
)
324341
return None
325342

326343

@@ -378,7 +395,7 @@ def _check_notifications(message: dict, murfey_db: Session) -> None:
378395
murfey_db.commit()
379396
murfey_db.close()
380397
if failures:
381-
_request_email(failures)
398+
_request_email(failures, message["session_id"], murfey_db)
382399
return None
383400

384401

0 commit comments

Comments
 (0)