11import logging
22import time
33from importlib .metadata import entry_points
4+ from pathlib import Path
45
56import ispyb .sqlalchemy ._auto_db_schema as ISPyBDB
67from sqlmodel import select
78from sqlmodel .orm .session import Session as SQLModelSession
89
9- import murfey .util .db as MurfeyDB
1010from murfey .server import _transport_object
1111from murfey .server .ispyb import ISPyBSession , get_session_id
12+ from murfey .util .db import DataCollectionGroup
1213
1314logger = logging .getLogger ("murfey.workflows.register_data_collection_group" )
1415
@@ -30,14 +31,14 @@ def run(message: dict, murfey_db: SQLModelSession) -> dict[str, bool]:
3031 )
3132
3233 if dcg_murfey := murfey_db .exec (
33- select (MurfeyDB . DataCollectionGroup )
34- .where (MurfeyDB . DataCollectionGroup .session_id == message ["session_id" ])
35- .where (MurfeyDB . DataCollectionGroup .tag == message .get ("tag" ))
34+ select (DataCollectionGroup )
35+ .where (DataCollectionGroup .session_id == message ["session_id" ])
36+ .where (DataCollectionGroup .tag == message .get ("tag" ))
3637 ).all ():
3738 dcgid = dcg_murfey [0 ].id
3839 else :
3940 if ispyb_session_id is None :
40- murfey_dcg = MurfeyDB . DataCollectionGroup (
41+ murfey_dcg = DataCollectionGroup (
4142 session_id = message ["session_id" ],
4243 tag = message .get ("tag" ),
4344 )
@@ -77,7 +78,7 @@ def run(message: dict, murfey_db: SQLModelSession) -> dict[str, bool]:
7778 "return_value" , None
7879 )
7980
80- murfey_dcg = MurfeyDB . DataCollectionGroup (
81+ murfey_dcg = DataCollectionGroup (
8182 id = dcgid ,
8283 atlas_id = atlas_id ,
8384 atlas = message .get ("atlas" , "" ),
@@ -90,6 +91,23 @@ def run(message: dict, murfey_db: SQLModelSession) -> dict[str, bool]:
9091 murfey_db .commit ()
9192 murfey_db .close ()
9293
94+ # Find out how many dcgs we have with this atlas
95+ if (
96+ message .get ("atlas" )
97+ and message .get ("sample" )
98+ and "atlas" in Path (message .get ("tag" , "/" )).parts
99+ ):
100+ dcgs_atlas = murfey_db .exec (
101+ select (DataCollectionGroup )
102+ .where (DataCollectionGroup .session_id == message ["session_id" ])
103+ .where (DataCollectionGroup .atlas == message ["atlas" ])
104+ .where (DataCollectionGroup .sample == message ["sample" ])
105+ ).all ()
106+ if len (dcgs_atlas ) > 1 :
107+ # Skip hooks if this is an atlas and there is a processing dcg present
108+ logger .info (f"Skipping data collection group hooks for { message ['tag' ]} " )
109+ return {"success" : True }
110+
93111 if dcg_hooks := entry_points (group = "murfey.hooks" , name = "data_collection_group" ):
94112 try :
95113 for hook in dcg_hooks :
0 commit comments