Skip to content

Commit 6e2c3b9

Browse files
authored
Replace client websocket (#716)
Replaced Client-Side Websocket Connection-Based Logging with HTTPX One The websocket connection between the client and the backend server has been unstable, prone to error, and unable to fulfil its role of sending logs to the backend for subsequent forwarding to the logging dashboard. In this PR, the log forwarding logic has been replaced by a HTTPX-based log handler that sends batches of logs to a backend FastAPI endpoint. It also removes the now-defunct websocket-related components from the client end. Simplifcation of pyproject.toml Dependency Keys Consequently, the optional dependency keys needed for our pyproject.toml file can also been streamlined. As of this PR, the client and instrument-server optional dependency keys are no longer needed, as the packages needed to run the instrument server are a subset of those needed to run the backend server, and have thus been integrated into the essential dependencies section. The documentation and GitHub workflows have thus been updated to reflect this.
1 parent ae75bb3 commit 6e2c3b9

File tree

25 files changed

+422
-432
lines changed

25 files changed

+422
-432
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ jobs:
7777
- name: Install Murfey
7878
run: |
7979
set -eux
80-
pip install --disable-pip-version-check -e "."[cicd,client,server,developer]
80+
pip install --disable-pip-version-check -e "."[cicd,server,developer]
8181
8282
- uses: shogo82148/actions-setup-mysql@v1
8383
with:

.github/workflows/publish-version.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
- name: Check current tag
2525
id: checkTag
2626
run: |
27-
pip install --disable-pip-version-check -e "."[cicd,client,server,developer]
27+
pip install --disable-pip-version-check -e "."[cicd,server,developer]
2828
VERSION=$(python -c "import murfey; print(murfey.__version__)")
2929
echo "newVersion=v$VERSION" >> $GITHUB_OUTPUT
3030

.github/workflows/version-bump.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
- name: Install package
4343
run: |
4444
set -eux
45-
pip install --disable-pip-version-check -e "."[cicd,client,server,developer]
45+
pip install --disable-pip-version-check -e "."[cicd,server,developer]
4646
- name: Run bumpversion and push tag
4747
env:
4848
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Dockerfiles/murfey-instrument-server

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ RUN apt-get update && \
3232
pip \
3333
build \
3434
importlib-metadata && \
35-
/venv/bin/python -m pip install /python-murfey[client]
35+
/venv/bin/python -m pip install /python-murfey
3636

3737

3838
# Transfer completed Murfey build to base image

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ then install using the following command.
1919
```text
2020
$ git clone [email protected]:DiamondLightSource/python-murfey.git
2121
$ cd python-murfey
22-
$ pip install -e .[client,server,developer]
22+
$ pip install -e .[server,developer]
2323
```
2424

2525
The packages included under the `[developer]` installation key contain some helpful tools to aid you with developing Murfey further:
@@ -43,7 +43,7 @@ $ murfey.server
4343
and connect the client with
4444

4545
```text
46-
$ murfey --server http://127.0.0.1:8000
46+
$ murfey.instrument_server --port 8000
4747
```
4848

4949
You can also install a client on a remote machine. This machine only needs to have

pyproject.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,12 @@ dependencies = [
4444
cicd = [
4545
"pytest-cov", # Used for generating PyTest coverage reports
4646
]
47-
client = [
48-
"websocket-client",
49-
]
5047
developer = [
5148
"bump-my-version", # Version control
5249
"ipykernel", # Enable interactive coding with VS Code and Jupyter Notebook
5350
"pre-commit", # Formatting, linting, type checking, etc.
5451
"pytest", # Test code functionality
52+
"pytest-asyncio", # For testing async functions
5553
"pytest-mock", # Additional mocking tools for unit tests
5654
]
5755
server = [

src/murfey/bootstrap/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def _download_to_file(url: str, outfile: str):
144144
murfey_hostname,
145145
"-i",
146146
f"{murfey_base}{url_path_for('bootstrap.pypi', 'get_pypi_index')}",
147-
"murfey[client]",
147+
"murfey",
148148
]
149149
)
150150
if result.returncode:

src/murfey/client/customlogging.py

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/murfey/client/multigrid_control.py

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import json
21
import logging
32
import subprocess
43
import threading
@@ -10,7 +9,6 @@
109
from typing import Dict, List, Optional
1110
from urllib.parse import urlparse
1211

13-
import murfey.client.websocket
1412
from murfey.client.analyser import Analyser
1513
from murfey.client.context import ensure_dcg_exists
1614
from murfey.client.contexts.spa import SPAModularContext
@@ -96,11 +94,6 @@ def __post_init__(self):
9694
self.rsync_processes = self.rsync_processes or {}
9795
self.analysers = self.analysers or {}
9896

99-
self.ws = murfey.client.websocket.WSApp(
100-
server=self.murfey_url,
101-
register_client=False,
102-
)
103-
10497
# Calculate the time offset between the client and the server
10598
current_time = datetime.now()
10699
server_timestamp = capture_get(
@@ -181,17 +174,6 @@ def clean_up_once_dormant(self, running_threads: list[threading.Thread]):
181174
if not success:
182175
log.warning(f"Could not delete database data for {self.session_id}")
183176

184-
# Send message to frontend to trigger a refresh
185-
self.ws.send(
186-
json.dumps(
187-
{
188-
"message": "refresh",
189-
"target": "sessions",
190-
"instrument_name": self.instrument_name,
191-
}
192-
)
193-
)
194-
195177
# Mark as dormant
196178
self.dormant = True
197179

@@ -289,15 +271,6 @@ def _start_rsyncer_multigrid(
289271
transfer=machine_data.get("data_transfer_enabled", True),
290272
restarted=str(source) in self.rsync_restarts,
291273
)
292-
self.ws.send(
293-
json.dumps(
294-
{
295-
"message": "refresh",
296-
"target": "rsyncer",
297-
"session_id": self.session_id,
298-
}
299-
)
300-
)
301274

302275
def _rsyncer_stopped(self, source: Path, explicit_stop: bool = False):
303276
if explicit_stop:

src/murfey/client/update.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def install_murfey(api_base: ParseResult, version: str) -> bool:
7878
path=f"{proxy_path}{url_path_for('bootstrap.pypi', 'get_pypi_index')}",
7979
query="",
8080
).geturl(),
81-
f"murfey[client]=={version}",
81+
f"murfey=={version}",
8282
]
8383
)
8484
return result.returncode == 0

0 commit comments

Comments
 (0)