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 src/murfey/server/api/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ def register_dc_group(
_transport_object.feedback_queue,
{
"register": "atlas_update",
"tag": dcg_instance.tag,
"atlas_id": dcg_instance.atlas_id,
"atlas": dcg_params.atlas,
"sample": dcg_params.sample,
Expand Down
21 changes: 21 additions & 0 deletions src/murfey/workflows/register_atlas_update.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import logging
from importlib.metadata import entry_points
from pathlib import Path

from sqlmodel import select
from sqlmodel.orm.session import Session as SQLModelSession

from murfey.server import _transport_object
from murfey.util.db import DataCollectionGroup

logger = logging.getLogger("murfey.workflows.register_atlas_update")

Expand All @@ -24,6 +27,24 @@ def run(
message["atlas_pixel_size"],
message["sample"],
)

# Find out how many dcgs we have with this atlas
if (
message.get("atlas")
and message.get("sample")
and "atlas" in Path(message.get("tag", "/")).parts
):
dcgs_atlas = murfey_db.exec(
select(DataCollectionGroup)
.where(DataCollectionGroup.session_id == message["session_id"])
.where(DataCollectionGroup.atlas == message["atlas"])
.where(DataCollectionGroup.sample == message["sample"])
).all()
if len(dcgs_atlas) > 1:
# Skip hooks if this is an atlas and there is a processing dcg present
logger.info(f"Skipping data collection group hooks for {message['tag']}")
return {"success": True}

if dcg_hooks := entry_points(group="murfey.hooks", name="data_collection_group"):
try:
for hook in dcg_hooks:
Expand Down
30 changes: 24 additions & 6 deletions src/murfey/workflows/register_data_collection_group.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import logging
import time
from importlib.metadata import entry_points
from pathlib import Path

import ispyb.sqlalchemy._auto_db_schema as ISPyBDB
from sqlmodel import select
from sqlmodel.orm.session import Session as SQLModelSession

import murfey.util.db as MurfeyDB
from murfey.server import _transport_object
from murfey.server.ispyb import ISPyBSession, get_session_id
from murfey.util.db import DataCollectionGroup

logger = logging.getLogger("murfey.workflows.register_data_collection_group")

Expand All @@ -30,14 +31,14 @@ def run(message: dict, murfey_db: SQLModelSession) -> dict[str, bool]:
)

if dcg_murfey := murfey_db.exec(
select(MurfeyDB.DataCollectionGroup)
.where(MurfeyDB.DataCollectionGroup.session_id == message["session_id"])
.where(MurfeyDB.DataCollectionGroup.tag == message.get("tag"))
select(DataCollectionGroup)
.where(DataCollectionGroup.session_id == message["session_id"])
.where(DataCollectionGroup.tag == message.get("tag"))
).all():
dcgid = dcg_murfey[0].id
else:
if ispyb_session_id is None:
murfey_dcg = MurfeyDB.DataCollectionGroup(
murfey_dcg = DataCollectionGroup(
session_id=message["session_id"],
tag=message.get("tag"),
)
Expand Down Expand Up @@ -71,7 +72,7 @@ def run(message: dict, murfey_db: SQLModelSession) -> dict[str, bool]:
"return_value", None
)

murfey_dcg = MurfeyDB.DataCollectionGroup(
murfey_dcg = DataCollectionGroup(
id=dcgid,
atlas_id=atlas_id,
atlas=message.get("atlas", ""),
Expand All @@ -84,6 +85,23 @@ def run(message: dict, murfey_db: SQLModelSession) -> dict[str, bool]:
murfey_db.commit()
murfey_db.close()

# Find out how many dcgs we have with this atlas
if (
message.get("atlas")
and message.get("sample")
and "atlas" in Path(message.get("tag", "/")).parts
):
dcgs_atlas = murfey_db.exec(
select(DataCollectionGroup)
.where(DataCollectionGroup.session_id == message["session_id"])
.where(DataCollectionGroup.atlas == message["atlas"])
.where(DataCollectionGroup.sample == message["sample"])
).all()
if len(dcgs_atlas) > 1:
# Skip hooks if this is an atlas and there is a processing dcg present
logger.info(f"Skipping data collection group hooks for {message['tag']}")
return {"success": True}

if dcg_hooks := entry_points(group="murfey.hooks", name="data_collection_group"):
try:
for hook in dcg_hooks:
Expand Down
3 changes: 3 additions & 0 deletions tests/server/api/test_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ def test_register_dc_group_processing_to_atlas(
"atlas_pixel_size": 1e-4,
"dcgid": 1,
"session_id": ExampleVisit.murfey_session_id,
"tag": "processing_tag",
},
)
mock_transport.send.assert_any_call(
Expand All @@ -189,6 +190,7 @@ def test_register_dc_group_processing_to_atlas(
"atlas_pixel_size": 1e-4,
"dcgid": 2,
"session_id": ExampleVisit.murfey_session_id,
"tag": "second_processing_tag",
},
)

Expand Down Expand Up @@ -395,6 +397,7 @@ def test_register_dc_group_new_atlas_with_searchmaps(
"atlas_pixel_size": 1e-4,
"dcgid": 1,
"session_id": ExampleVisit.murfey_session_id,
"tag": "processing_tag",
},
)

Expand Down