Skip to content

Commit 7942a7f

Browse files
committed
API setup to pass visit end times to multigrid controller for use with rsyncers
1 parent 794ae7f commit 7942a7f

File tree

6 files changed

+18
-4
lines changed

6 files changed

+18
-4
lines changed

src/murfey/client/multigrid_control.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ class MultigridController:
4848
data_collection_parameters: dict = field(default_factory=lambda: {})
4949
token: str = ""
5050
_machine_config: dict = field(default_factory=lambda: {})
51+
visit_end_time: Optional[datetime] = None
52+
end_time_grace_period: int = 0
5153

5254
def __post_init__(self):
5355
if self.token:
@@ -277,6 +279,8 @@ def _start_rsyncer(
277279
stop_callback=self._rsyncer_stopped,
278280
do_transfer=self.do_transfer,
279281
remove_files=remove_files,
282+
end_time=self.visit_end_time,
283+
grace_period=self.end_time_grace_period,
280284
)
281285

282286
def rsync_result(update: RSyncerUpdate):

src/murfey/instrument_server/api.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ def setup_multigrid_watcher(
160160
token=tokens.get(session_id, "token"),
161161
data_collection_parameters=data_collection_parameters.get(label, {}),
162162
rsync_restarts=watcher_spec.rsync_restarts,
163+
visit_end_time=watcher_spec.visit_end_time,
164+
end_time_grace_period=watcher_spec.grace_period,
163165
)
164166
watcher_spec.source.mkdir(exist_ok=True)
165167
machine_config = requests.get(

src/murfey/server/api/instrument.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,8 @@ async def setup_multigrid_watcher(
9898
session_id: MurfeySessionID, watcher_spec: MultigridWatcherSetup, db=murfey_db
9999
):
100100
data = {}
101-
instrument_name = (
102-
db.exec(select(Session).where(Session.id == session_id)).one().instrument_name
103-
)
101+
session = db.exec(select(Session).where(Session.id == session_id)).one()
102+
instrument_name = session.instrument_name
104103
machine_config = get_machine_config(instrument_name=instrument_name)[
105104
instrument_name
106105
]
@@ -130,6 +129,8 @@ async def setup_multigrid_watcher(
130129
str(k): v for k, v in watcher_spec.destination_overrides.items()
131130
},
132131
"rsync_restarts": watcher_spec.rsync_restarts,
132+
"visit_end_time": session.visit_end_time,
133+
"grace_period": machine_config.grace_period,
133134
},
134135
headers={
135136
"Authorization": f"Bearer {instrument_server_tokens[session_id]['access_token']}"

src/murfey/util/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ class MachineConfig(BaseModel, extra=Extra.allow): # type: ignore
7171

7272
notifications_queue: str = "pato_notification"
7373

74+
grace_period: int = 0
75+
7476

7577
def from_file(config_file_path: Path, instrument: str = "") -> Dict[str, MachineConfig]:
7678
with open(config_file_path, "r") as config_stream:

src/murfey/util/db.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
of the sessions that Murfey is overseeing, along with the relationships between them.
44
"""
55

6+
from datetime import datetime
67
from typing import List, Optional
78

89
import sqlalchemy
@@ -48,6 +49,7 @@ class Session(SQLModel, table=True): # type: ignore
4849
started: bool = Field(default=False)
4950
current_gain_ref: str = Field(default="")
5051
instrument_name: str = Field(default="")
52+
visit_end_time: Optional[datetime] = Field(default=None)
5153

5254
# CLEM Workflow
5355

src/murfey/util/instrument_models.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from datetime import datetime
12
from pathlib import Path
2-
from typing import Dict, List
3+
from typing import Dict, List, Optional
34

45
from pydantic import BaseModel
56

@@ -15,3 +16,5 @@ class MultigridWatcherSpec(BaseModel):
1516
skip_existing_processing: bool = False
1617
destination_overrides: Dict[Path, str] = {}
1718
rsync_restarts: List[str] = []
19+
visit_end_time: Optional[datetime] = None
20+
grace_period: int = 0

0 commit comments

Comments
 (0)