-
Notifications
You must be signed in to change notification settings - Fork 1
Add endpoint which can gather extra rsyncer information #545
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
bc44840
95eab5b
8142442
c3b5371
58129f9
202a244
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,7 +23,7 @@ | |
| from murfey.server.murfey_db import murfey_db | ||
| from murfey.util import secure_path | ||
| from murfey.util.config import get_machine_config | ||
| from murfey.util.db import Session, SessionProcessingParameters | ||
| from murfey.util.db import RsyncInstance, Session, SessionProcessingParameters | ||
| from murfey.util.models import File, MultigridWatcherSetup | ||
|
|
||
| # Create APIRouter class object | ||
|
|
@@ -407,3 +407,67 @@ | |
| ) as resp: | ||
| data = await resp.json() | ||
| return data | ||
|
|
||
|
|
||
| class RSyncerInfo(BaseModel): | ||
| source: str | ||
| num_files_transferred: int | ||
| num_files_in_queue: int | ||
| alive: bool | ||
| stopping: bool | ||
| destination: str | ||
| tag: str | ||
| files_transferred: int | ||
| files_counted: int | ||
| transferring: bool | ||
| session_id: int | ||
|
|
||
|
|
||
| @router.get("/instruments/{instrument_name}/sessions/{session_id}/rsyncer_info") | ||
| async def get_rsyncer_info( | ||
| instrument_name: str, session_id: MurfeySessionID, db=murfey_db | ||
| ) -> List[RSyncerInfo]: | ||
| data = [] | ||
| machine_config = get_machine_config(instrument_name=instrument_name)[ | ||
| instrument_name | ||
| ] | ||
| rsync_instances = db.exec( | ||
| select(RsyncInstance).where(RsyncInstance.session_id == session_id) | ||
| ).all() | ||
| if machine_config.instrument_server_url: | ||
| try: | ||
| async with lock: | ||
| token = instrument_server_tokens[session_id]["access_token"] | ||
| async with aiohttp.ClientSession() as clientsession: | ||
| async with clientsession.get( | ||
| f"{machine_config.instrument_server_url}/sessions/{session_id}/rsyncer_info", | ||
| headers={"Authorization": f"Bearer {token}"}, | ||
| ) as resp: | ||
| data = await resp.json() | ||
| except KeyError: | ||
| data = [] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add a debug/warning log, in case it's not performing what we expected?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this case this is to catch the case where the instrument server has disconnected. Then I want |
||
| except Exception: | ||
| log.warning( | ||
| "Exception encountered gathering rsyncer info from the instrument server", | ||
| exc_info=True, | ||
| ) | ||
| combined_data = [] | ||
| data_source_lookup = {d["source"]: d for d in data} | ||
| for ri in rsync_instances: | ||
| d = data_source_lookup.get(ri.source, {}) | ||
| combined_data.append( | ||
| RSyncerInfo( | ||
| source=ri.source, | ||
| num_files_transferred=d.get("num_files_transferred", 0), | ||
| num_files_in_queue=d.get("num_files_in_queue", 0), | ||
| alive=d.get("alive", False), | ||
| stopping=d.get("stopping", True), | ||
| destination=ri.destination, | ||
| tag=ri.tag, | ||
| files_transferred=ri.files_transferred, | ||
| files_counted=ri.files_counted, | ||
| transferring=ri.transferring, | ||
| session_id=session_id, | ||
| ) | ||
| ) | ||
| return combined_data | ||
Uh oh!
There was an error while loading. Please reload this page.