Skip to content
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

add ispyb simulator plugin #125

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
3 changes: 3 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/DiamondLightSource/ispyb-api/pull/163>`_) to call a recipe
before and after creation of data

0.10.0 (2021-10-04)
-------------------
Expand Down
4 changes: 4 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
46 changes: 46 additions & 0 deletions src/zocalo/ispyb/simulator.py
Original file line number Diff line number Diff line change
@@ -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"},
},
)