diff --git a/HISTORY.rst b/HISTORY.rst index 080ff44..09976d4 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -6,6 +6,9 @@ Unreleased ---------- * Use ``argparse`` for all command line tools and make use of ``workflows`` transport argument injection. Minimum ``workflows`` version is now 2.14 +* Add a zocalo plugin for ``ispyb.simulate`` + (`#163 `_) to call a recipe + before and after creation of data 0.10.0 (2021-10-04) ------------------- diff --git a/setup.cfg b/setup.cfg index 13b12c3..705aceb 100644 --- a/setup.cfg +++ b/setup.cfg @@ -61,6 +61,10 @@ zocalo.configuration.plugins = jmx = zocalo.configuration.plugin_jmx:JMX zocalo.wrappers = dummy = zocalo.wrapper:DummyWrapper +ispyb.simulator.before_datacollection = + zocalo = zocalo.ispyb.simulator:before +ispyb.simulator.after_datacollection = + zocalo = zocalo.ispyb.simulator:after [options.packages.find] where = src diff --git a/src/zocalo/ispyb/simulator.py b/src/zocalo/ispyb/simulator.py new file mode 100644 index 0000000..a9b0893 --- /dev/null +++ b/src/zocalo/ispyb/simulator.py @@ -0,0 +1,46 @@ +import logging + +import workflows.transport +import zocalo.configuration + + +logger = logging.getLogger(__name__) + + +def _send_message(message: dict, headers={}): + transport = workflows.transport.lookup(workflows.transport.default_transport)() + try: + transport.connect() + transport.send("processing_recipe", message, headers=headers) + transport.disconnect() + except Exception: + logger.warning("Cant connect to workflow transport") + + +def _get_recipe(event: str): + zc = zocalo.configuration.from_file() + zc.activate() + + recipe = "mimas" + if zc.storage: + recipe = zc.storage.get("ispyb.simulator", {}).get(event, "mimas") + + return recipe + + +def before(dcid: int): + _send_message( + { + "recipes": [_get_recipe("recipe_before")], + "parameters": {"ispyb_dcid": dcid, "event": "start"}, + }, + ) + + +def after(dcid: int): + _send_message( + { + "recipes": [_get_recipe("recipe_after")], + "parameters": {"ispyb_dcid": dcid, "event": "end"}, + }, + )