Skip to content

Commit 72670d4

Browse files
authored
Allow a controller to be "abandoned" (#582)
* Functionality to abandon multigrid controller (i.e. stop all threads) * Endpoints to abandon controller for session
1 parent efda46c commit 72670d4

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

src/murfey/client/multigrid_control.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,14 @@ async def dormancy_check(self):
122122
log.warning(f"Could not delete database data for {self.session_id}")
123123
self.dormant = True
124124

125+
def abandon(self):
126+
for a in self.analysers.values():
127+
a.request_stop()
128+
for w in self._environment.watchers.values():
129+
w.request_stop()
130+
for p in self.rsync_processes.values():
131+
p.request_stop()
132+
125133
def finalise(self):
126134
for a in self.analysers.values():
127135
a.request_stop()

src/murfey/client/rsync.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@ def stop(self):
182182
self.thread.join()
183183
logger.debug("RSync thread stop completed")
184184

185+
def request_stop(self):
186+
self._stopping = True
187+
self._halt_thread = True
188+
185189
def finalise(
186190
self,
187191
thread: bool = True,

src/murfey/instrument_server/api.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,12 @@ def remove_rsyncer(session_id: MurfeySessionID, rsyncer_source: RsyncerSource):
220220
return {"success": True}
221221

222222

223+
@router.post("/sessions/{session_id}/abandon_controller")
224+
def abandon_controller(session_id: MurfeySessionID):
225+
controllers[session_id].abandon()
226+
return {"success": True}
227+
228+
223229
@router.post("/sessions/{session_id}/finalise_rsyncer")
224230
def finalise_rsyncer(session_id: MurfeySessionID, rsyncer_source: RsyncerSource):
225231
controllers[session_id]._finalise_rsyncer(rsyncer_source.source)

src/murfey/server/api/instrument.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,27 @@ async def finalise_session(session_id: MurfeySessionID, db=murfey_db):
395395
return data
396396

397397

398+
@router.post("/sessions/{session_id}/abandon_session")
399+
async def abandon_session(session_id: MurfeySessionID, db=murfey_db):
400+
data = {}
401+
instrument_name = (
402+
db.exec(select(Session).where(Session.id == session_id)).one().instrument_name
403+
)
404+
machine_config = get_machine_config(instrument_name=instrument_name)[
405+
instrument_name
406+
]
407+
if machine_config.instrument_server_url:
408+
async with aiohttp.ClientSession() as clientsession:
409+
async with clientsession.post(
410+
f"{machine_config.instrument_server_url}/sessions/{session_id}/abandon_controller",
411+
headers={
412+
"Authorization": f"Bearer {instrument_server_tokens[session_id]['access_token']}"
413+
},
414+
) as resp:
415+
data = await resp.json()
416+
return data
417+
418+
398419
@router.post("/sessions/{session_id}/remove_rsyncer")
399420
async def remove_rsyncer(
400421
session_id: MurfeySessionID, rsyncer_source: RsyncerSource, db=murfey_db

0 commit comments

Comments
 (0)