-
Notifications
You must be signed in to change notification settings - Fork 1
Refactor feedback-callback and update package dependencies #688
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 23 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
b13c4ad
Modified workflow entry points to return a dictionary so that we can …
tieneupin 51717c4
Migrated 'data_collection_group' feedback-callback block into its own…
tieneupin 97fef8d
Migrated 'data_collection' feedback-callback block into its own workf…
tieneupin 005f2c6
Merged recent changes from 'main' branch
tieneupin e5e4506
Updated tomo picking workflow to return a dict instead of a boolean
tieneupin add807f
Fixed wrong extraction of results from 'do_insert_data_collection' ca…
tieneupin 00730cb
Added logs
tieneupin 33d84a2
Migrated 'atlas_update' feedback-callback block to its own workflows …
tieneupin 9034eb8
'do_create_ispyb_job' function in TransportManager should return a di…
tieneupin 4591e76
Migrated 'processing_job' feedback-callback block to its own workflow…
tieneupin 95512ff
'ExtendedRecord' class and '_register' set of functions can now be re…
tieneupin a71358c
Added logs
tieneupin b39fd01
Removed previous version restrictions on fastapi and stomp-py due to …
tieneupin 424dafe
Added initial test for 'feedback_callback' block to check that entry …
tieneupin c0115ad
Added unit test for 'register_atlas_update'
tieneupin 83dfb75
Annotated int only needed on the API endpoints that call 'register_gr…
tieneupin a42f8d9
Import module for test only after mocking out the functions used to g…
tieneupin ce56f3a
Added unit test for 'register_data_collection' workflow
tieneupin 8057a5c
Removed unneeded 'if _transport_object:' logic block
tieneupin e83b703
Fixed broken test iterations for 'register_data_collection'
tieneupin 62d4724
Added unit test for 'register_data_collection_group' workflow
tieneupin 7de09ab
Some formatting
tieneupin cb94acb
Added unit test for 'register_processing_job' workflow
tieneupin 55fda57
Removed unreachable code found by CodeQL
tieneupin bbf6956
'backports.entry_points_selectable' no longer needed as a package dep…
tieneupin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,4 +78,4 @@ def submit_cluster_request( | |
| }, | ||
| new_connection=True, | ||
| ) | ||
| return True | ||
| return {"success": True} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import logging | ||
|
|
||
| from backports.entry_points_selectable import entry_points | ||
| from sqlmodel.orm.session import Session as SQLModelSession | ||
|
|
||
| from murfey.server import _transport_object | ||
|
|
||
| logger = logging.getLogger("murfey.workflows.register_atlas_update") | ||
|
|
||
|
|
||
| def run( | ||
| message: dict, | ||
| murfey_db: SQLModelSession, # Defined for compatibility but unused | ||
| demo: bool = False, | ||
| ): | ||
| if _transport_object is None: | ||
| logger.error("Unable to find transport manager") | ||
| return {"success": False, "requeue": False} | ||
|
|
||
| logger.info(f"Registering updated atlas: \n{message}") | ||
|
|
||
| _transport_object.do_update_atlas( | ||
| message["atlas_id"], | ||
| message["atlas"], | ||
| message["atlas_pixel_size"], | ||
| message["sample"], | ||
| ) | ||
| if dcg_hooks := entry_points().select( | ||
| group="murfey.hooks", name="data_collection_group" | ||
| ): | ||
| try: | ||
| for hook in dcg_hooks: | ||
| hook.load()(message["dcgid"], session_id=message["session_id"]) | ||
| except Exception: | ||
| logger.error("Call to data collection group hook failed", exc_info=True) | ||
| return {"success": True} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| import logging | ||
|
|
||
| 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 import sanitise | ||
|
|
||
| logger = logging.getLogger("murfey.workflows.register_data_collection") | ||
|
|
||
|
|
||
| def run( | ||
| message: dict, murfey_db: SQLModelSession, demo: bool = False | ||
| ) -> dict[str, bool]: | ||
| # Fail immediately if transport manager was not provided | ||
| if _transport_object is None: | ||
| logger.error("Unable to find transport manager") | ||
| return {"success": False, "requeue": False} | ||
|
|
||
| logger.info(f"Registering the following data collection: \n{message}") | ||
|
|
||
| murfey_session_id = message["session_id"] | ||
| ispyb_session_id = get_session_id( | ||
| microscope=message["microscope"], | ||
| proposal_code=message["proposal_code"], | ||
| proposal_number=message["proposal_number"], | ||
| visit_number=message["visit_number"], | ||
| db=ISPyBSession(), | ||
| ) | ||
| dcg = murfey_db.exec( | ||
| select(MurfeyDB.DataCollectionGroup) | ||
| .where(MurfeyDB.DataCollectionGroup.session_id == murfey_session_id) | ||
| .where(MurfeyDB.DataCollectionGroup.tag == message["source"]) | ||
| ).all() | ||
| if dcg: | ||
| dcgid = dcg[0].id | ||
| # flush_data_collections(message["source"], murfey_db) | ||
| else: | ||
| logger.warning( | ||
| "No data collection group ID was found for image directory " | ||
| f"{sanitise(message['image_directory'])} and source " | ||
| f"{sanitise(message['source'])}" | ||
| ) | ||
| return {"success": False, "requeue": True} | ||
|
|
||
| if dc_murfey := murfey_db.exec( | ||
| select(MurfeyDB.DataCollection) | ||
| .where(MurfeyDB.DataCollection.tag == message.get("tag")) | ||
| .where(MurfeyDB.DataCollection.dcg_id == dcgid) | ||
| ).all(): | ||
| dcid = dc_murfey[0].id | ||
| else: | ||
| if ispyb_session_id is None: | ||
| murfey_dc = MurfeyDB.DataCollection( | ||
| tag=message.get("tag"), | ||
| dcg_id=dcgid, | ||
| ) | ||
| else: | ||
| record = ISPyBDB.DataCollection( | ||
| SESSIONID=ispyb_session_id, | ||
| experimenttype=message["experiment_type"], | ||
| imageDirectory=message["image_directory"], | ||
| imageSuffix=message["image_suffix"], | ||
| voltage=message["voltage"], | ||
| dataCollectionGroupId=dcgid, | ||
| pixelSizeOnImage=message["pixel_size"], | ||
| imageSizeX=message["image_size_x"], | ||
| imageSizeY=message["image_size_y"], | ||
| slitGapHorizontal=message.get("slit_width"), | ||
| magnification=message.get("magnification"), | ||
| exposureTime=message.get("exposure_time"), | ||
| totalExposedDose=message.get("total_exposed_dose"), | ||
| c2aperture=message.get("c2aperture"), | ||
| phasePlate=int(message.get("phase_plate", 0)), | ||
| ) | ||
| dcid = _transport_object.do_insert_data_collection( | ||
| record, | ||
| tag=( | ||
| message.get("tag") | ||
| if message["experiment_type"] == "tomography" | ||
| else "" | ||
| ), | ||
| ).get("return_value", None) | ||
| murfey_dc = MurfeyDB.DataCollection( | ||
| id=dcid, | ||
| tag=message.get("tag"), | ||
| dcg_id=dcgid, | ||
| ) | ||
| murfey_db.add(murfey_dc) | ||
| murfey_db.commit() | ||
| dcid = murfey_dc.id | ||
| murfey_db.close() | ||
|
|
||
| if dcid is None: | ||
| logger.error( | ||
| "Failed to register the following data collection: \n" | ||
| f"{message} \n" | ||
| "Requeueing message" | ||
| ) | ||
| return {"success": False, "requeue": True} | ||
| return {"success": True} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.