Skip to content
Merged
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
27 changes: 17 additions & 10 deletions src/murfey/client/multigrid_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from typing import Dict, List, Optional
from urllib.parse import quote, urlparse

import aiohttp
import requests

import murfey.client.websocket
Expand All @@ -22,7 +21,7 @@
from murfey.client.watchdir import DirWatcher
from murfey.util import posix_path
from murfey.util.api import url_path_for
from murfey.util.client import capture_post, get_machine_config_client
from murfey.util.client import capture_delete, capture_post, get_machine_config_client

log = logging.getLogger("murfey.client.mutligrid_control")

Expand Down Expand Up @@ -117,7 +116,7 @@
self.multigrid_watcher_active = False
self.dormancy_check()

async def dormancy_check(self):
def dormancy_check(self):
if not self.multigrid_watcher_active:
if (
all(r._finalised for r in self.rsync_processes.values())
Expand All @@ -126,14 +125,22 @@
w.thread.is_alive() for w in self._environment.watchers.values()
)
):
async with aiohttp.ClientSession() as clientsession:
async with clientsession.delete(

def call_remove_session():
response = capture_delete(

Check warning on line 130 in src/murfey/client/multigrid_control.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/client/multigrid_control.py#L129-L130

Added lines #L129 - L130 were not covered by tests
f"{self._environment.url.geturl()}{url_path_for('session_control.router', 'remove_session', session_id=self.session_id)}",
json={"access_token": self.token, "token_type": "bearer"},
) as response:
success = response.status == 200
if not success:
log.warning(f"Could not delete database data for {self.session_id}")
)
success = response.status_code == 200 if response else False

Check warning on line 133 in src/murfey/client/multigrid_control.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/client/multigrid_control.py#L133

Added line #L133 was not covered by tests
if not success:
log.warning(

Check warning on line 135 in src/murfey/client/multigrid_control.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/client/multigrid_control.py#L135

Added line #L135 was not covered by tests
f"Could not delete database data for {self.session_id}"
)

dormancy_thread = threading.Thread(

Check warning on line 139 in src/murfey/client/multigrid_control.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/client/multigrid_control.py#L139

Added line #L139 was not covered by tests
name=f"Session deletion thread {self.session_id}",
target=call_remove_session,
)
dormancy_thread.start()

Check warning on line 143 in src/murfey/client/multigrid_control.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/client/multigrid_control.py#L143

Added line #L143 was not covered by tests
self.dormant = True

def abandon(self):
Expand Down
14 changes: 14 additions & 0 deletions src/murfey/util/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,20 @@
return response


def capture_delete(url: str) -> Optional[requests.Response]:
try:
response = requests.delete(url)
except Exception as e:
logger.error(f"Exception encountered in delete of {url}: {e}")
response = None

Check warning on line 131 in src/murfey/util/client.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/util/client.py#L127-L131

Added lines #L127 - L131 were not covered by tests
if response and response.status_code != 200:
logger.warning(

Check warning on line 133 in src/murfey/util/client.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/util/client.py#L133

Added line #L133 was not covered by tests
f"Response to delete of {url} had status code {response.status_code}. "
f"The reason given was {response.reason}"
)
return response

Check warning on line 137 in src/murfey/util/client.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/util/client.py#L137

Added line #L137 was not covered by tests


def set_default_acquisition_output(
new_output_dir: Path,
software_settings_output_directories: dict[str, list[str]],
Expand Down