Skip to content

Commit 993568c

Browse files
authored
Separate multigrid watcher setup endpoint from watcher start endpoint (#566)
Allows better control over when watching starts so that early starting (i.e. before processing parameter specification) can be avoided
1 parent a32d16e commit 993568c

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/murfey/instrument_server/api.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def check_token(session_id: MurfeySessionID):
138138

139139

140140
@router.post("/sessions/{session_id}/multigrid_watcher")
141-
def start_multigrid_watcher(
141+
def setup_multigrid_watcher(
142142
session_id: MurfeySessionID, watcher_spec: MultigridWatcherSpec
143143
):
144144
if controllers.get(session_id) is not None:
@@ -182,6 +182,13 @@ def start_multigrid_watcher(
182182
watchers[session_id].subscribe(
183183
controllers[session_id]._multigrid_watcher_finalised, final=True
184184
)
185+
return {"success": True}
186+
187+
188+
@router.post("/sessions/{session_id}/start_multigrid_watcher")
189+
def start_multigrid_watcher(session_id: MurfeySessionID):
190+
if watchers.get(session_id) is None:
191+
return {"success": False}
185192
watchers[session_id].start()
186193
return {"success": True}
187194

src/murfey/server/api/instrument.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ async def check_if_session_is_active(instrument_name: str, session_id: int):
9494

9595

9696
@router.post("/sessions/{session_id}/multigrid_watcher")
97-
async def start_multigrid_watcher(
97+
async def setup_multigrid_watcher(
9898
session_id: MurfeySessionID, watcher_spec: MultigridWatcherSetup, db=murfey_db
9999
):
100100
data = {}
@@ -139,6 +139,27 @@ async def start_multigrid_watcher(
139139
return data
140140

141141

142+
@router.post("/sessions/{session_id}/start_multigrid_watcher")
143+
async def start_multigrid_watcher(session_id: MurfeySessionID, db=murfey_db):
144+
data = {}
145+
instrument_name = (
146+
db.exec(select(Session).where(Session.id == session_id)).one().instrument_name
147+
)
148+
machine_config = get_machine_config(instrument_name=instrument_name)[
149+
instrument_name
150+
]
151+
if machine_config.instrument_server_url:
152+
async with aiohttp.ClientSession() as clientsession:
153+
async with clientsession.post(
154+
f"{machine_config.instrument_server_url}/sessions/{session_id}/start_multigrid_watcher",
155+
headers={
156+
"Authorization": f"Bearer {instrument_server_tokens[session_id]['access_token']}"
157+
},
158+
) as resp:
159+
data = await resp.json()
160+
return data
161+
162+
142163
class ProvidedProcessingParameters(BaseModel):
143164
dose_per_frame: float
144165
extract_downscale: bool = True

0 commit comments

Comments
 (0)