-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsimulator.py
More file actions
46 lines (33 loc) · 1.04 KB
/
simulator.py
File metadata and controls
46 lines (33 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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"},
},
)