Skip to content

Commit 7b7e12b

Browse files
committed
Don't pass machine config through the 'MultigridWatcherSpec' model between backend and instrument servers; get machine config via request instead
1 parent 5d7d2fe commit 7b7e12b

File tree

3 files changed

+12
-19
lines changed

3 files changed

+12
-19
lines changed

src/murfey/instrument_server/api.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,16 @@ def check_token(session_id: MurfeySessionID):
141141
def setup_multigrid_watcher(
142142
session_id: MurfeySessionID, watcher_spec: MultigridWatcherSpec
143143
):
144+
# Return True if controllers are already set up
144145
if controllers.get(session_id) is not None:
145146
return {"success": True}
147+
148+
# Load machine config as dictionary
149+
machine_config: dict[str, Any] = requests.get(
150+
f"{_get_murfey_url()}/instruments/{sanitise_nonpath(watcher_spec.instrument_name)}/machine",
151+
headers={"Authorization": f"Bearer {tokens[session_id]}"},
152+
).json()
153+
146154
label = watcher_spec.label
147155
for sid, controller in controllers.items():
148156
if controller.dormant:
@@ -156,22 +164,19 @@ def setup_multigrid_watcher(
156164
demo=True,
157165
do_transfer=True,
158166
processing_enabled=not watcher_spec.skip_existing_processing,
159-
_machine_config=watcher_spec.configuration.dict(),
167+
_machine_config=machine_config,
160168
token=tokens.get(session_id, "token"),
161169
data_collection_parameters=data_collection_parameters.get(label, {}),
162170
rsync_restarts=watcher_spec.rsync_restarts,
163171
visit_end_time=watcher_spec.visit_end_time,
164172
)
165173
watcher_spec.source.mkdir(exist_ok=True)
166-
machine_config = requests.get(
167-
f"{_get_murfey_url()}/instruments/{sanitise_nonpath(watcher_spec.instrument_name)}/machine",
168-
headers={"Authorization": f"Bearer {tokens[session_id]}"},
169-
).json()
174+
170175
for d in machine_config.get("create_directories", []):
171176
(watcher_spec.source / d).mkdir(exist_ok=True)
172177
watchers[session_id] = MultigridDirWatcher(
173178
watcher_spec.source,
174-
watcher_spec.configuration.dict(),
179+
machine_config,
175180
skip_existing_processing=watcher_spec.skip_existing_processing,
176181
)
177182
watchers[session_id].subscribe(

src/murfey/server/api/instrument.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,22 +106,13 @@ async def setup_multigrid_watcher(
106106
if machine_config.instrument_server_url:
107107
session = db.exec(select(Session).where(Session.id == session_id)).one()
108108
visit = session.visit
109-
_config = {
110-
"acquisition_software": machine_config.acquisition_software,
111-
"calibrations": machine_config.calibrations,
112-
"data_directories": [str(k) for k in machine_config.data_directories],
113-
"create_directories": [str(k) for k in machine_config.create_directories],
114-
"rsync_basepath": str(machine_config.rsync_basepath),
115-
"visit": visit,
116-
"default_model": str(machine_config.default_model),
117-
}
109+
118110
async with aiohttp.ClientSession() as clientsession:
119111
async with clientsession.post(
120112
f"{machine_config.instrument_server_url}/sessions/{session_id}/multigrid_watcher",
121113
json={
122114
"source": str(secure_path(watcher_spec.source / visit)),
123115
"visit": visit,
124-
"configuration": _config,
125116
"label": visit,
126117
"instrument_name": instrument_name,
127118
"skip_existing_processing": watcher_spec.skip_existing_processing,

src/murfey/util/instrument_models.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@
44

55
from pydantic import BaseModel
66

7-
from murfey.util.config import MachineConfig
8-
97

108
class MultigridWatcherSpec(BaseModel):
119
source: Path
12-
configuration: MachineConfig
1310
label: str
1411
visit: str
1512
instrument_name: str

0 commit comments

Comments
 (0)