Skip to content

Commit 6032dde

Browse files
committed
Move session deletion to the point where the multigrid controller becomes dormant and make it asynchronous
1 parent c469211 commit 6032dde

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ developer = [
5353
"pytest", # Test code functionality
5454
]
5555
instrument-server = [
56+
"aiohttp",
5657
"fastapi[standard]",
5758
"python-jose[cryptography]",
5859
"uvicorn[standard]",

src/murfey/client/multigrid_control.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from typing import Dict, List, Optional
1010
from urllib.parse import urlparse
1111

12+
import aiohttp
1213
import requests
1314

1415
import murfey.client.websocket
@@ -101,7 +102,7 @@ def _multigrid_watcher_finalised(self):
101102
self.multigrid_watcher_active = False
102103
self.dormancy_check()
103104

104-
def dormancy_check(self):
105+
async def dormancy_check(self):
105106
if not self.multigrid_watcher_active:
106107
if (
107108
all(r._finalised for r in self.rsync_processes.values())
@@ -110,6 +111,14 @@ def dormancy_check(self):
110111
w.thread.is_alive() for w in self._environment.watchers.values()
111112
)
112113
):
114+
async with aiohttp.ClientSession() as clientsession:
115+
async with clientsession.delete(
116+
f"{self._environment.url.geturl()}/sessions/{self.session_id}",
117+
json={"access_token": self.token, "token_type": "bearer"},
118+
) as response:
119+
success = response.status == 200
120+
if not success:
121+
log.warning(f"Could not delete database data for {self.session_id}")
113122
self.dormant = True
114123

115124
def finalise(self):

src/murfey/instrument_server/api.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,6 @@ def start_multigrid_watcher(
147147
for sid, controller in controllers.items():
148148
if controller.dormant:
149149
del controllers[sid]
150-
requests.delete(
151-
f"{_get_murfey_url()}/sessions/{sanitise_nonpath(str(sid))}",
152-
headers={"Authorization": f"Bearer {tokens[sid]}"},
153-
)
154150
controllers[session_id] = MultigridController(
155151
[],
156152
watcher_spec.visit,

0 commit comments

Comments
 (0)