|
3 | 3 | import asyncio |
4 | 4 | import datetime |
5 | 5 | import logging |
6 | | -import urllib |
7 | 6 | from pathlib import Path |
8 | 7 | from typing import Annotated, List, Optional |
| 8 | +from urllib.parse import quote |
9 | 9 |
|
10 | 10 | import aiohttp |
11 | 11 | from fastapi import APIRouter, Depends |
@@ -418,7 +418,7 @@ async def update_visit_end_time( |
418 | 418 | if machine_config.instrument_server_url: |
419 | 419 | async with aiohttp.ClientSession() as clientsession: |
420 | 420 | async with clientsession.post( |
421 | | - f"{machine_config.instrument_server_url}{url_path_for('api.router', 'update_multigrid_controller_visit_end_time', session_id=session_id)}?end_time={urllib.parse.quote(end_time.isoformat())}", |
| 421 | + f"{machine_config.instrument_server_url}{url_path_for('api.router', 'update_multigrid_controller_visit_end_time', session_id=session_id)}?end_time={quote(end_time.isoformat())}", |
422 | 422 | headers={ |
423 | 423 | "Authorization": f"Bearer {instrument_server_tokens[session_id]['access_token']}" |
424 | 424 | }, |
@@ -506,16 +506,41 @@ async def restart_rsyncer( |
506 | 506 | async def flush_skipped_rsyncer( |
507 | 507 | session_id: MurfeySessionID, rsyncer_source: RsyncerSource, db=murfey_db |
508 | 508 | ): |
509 | | - data = {} |
510 | | - instrument_name = ( |
511 | | - db.exec(select(Session).where(Session.id == session_id)).one().instrument_name |
512 | | - ) |
| 509 | + # Load data for session |
| 510 | + session_entry = db.exec(select(Session).where(Session.id == session_id)).one() |
| 511 | + instrument_name = session_entry.instrument_name |
| 512 | + |
| 513 | + # Define a new visit end time that's slightly ahead of current time |
| 514 | + new_end_time = datetime.datetime.now().replace( |
| 515 | + second=0, microsecond=0 |
| 516 | + ) + datetime.timedelta(minutes=5) |
| 517 | + # Update the stored visit end time if the new one exceeds it |
| 518 | + if session_entry.visit_end_time: |
| 519 | + if new_end_time > session_entry.visit_end_time: |
| 520 | + session_entry.visit_end_time = new_end_time |
| 521 | + db.add(session_entry) |
| 522 | + db.commit() |
| 523 | + |
| 524 | + # Send request to flush rsyncer |
| 525 | + data: dict = {} |
| 526 | + update_result: dict = {} |
513 | 527 | machine_config = get_machine_config(instrument_name=instrument_name)[ |
514 | 528 | instrument_name |
515 | 529 | ] |
516 | 530 | if isinstance(session_id, int): |
517 | 531 | if machine_config.instrument_server_url: |
518 | 532 | async with aiohttp.ClientSession() as clientsession: |
| 533 | + # Send request to instrument server to update multigrid controller |
| 534 | + async with clientsession.post( |
| 535 | + f"{machine_config.instrument_server_url}{url_path_for('api.router', 'update_multigrid_controller_visit_end_time', session_id=session_id)}?end_time={quote(session_entry.visit_end_time.isoformat())}", |
| 536 | + headers={ |
| 537 | + "Authorization": f"Bearer {instrument_server_tokens[session_id]['access_token']}" |
| 538 | + }, |
| 539 | + ) as resp: |
| 540 | + update_result = await resp.json() |
| 541 | + if not update_result.get("success", False): |
| 542 | + return {"success": False} |
| 543 | + # Send request to flush the rsyncer |
519 | 544 | async with clientsession.post( |
520 | 545 | f"{machine_config.instrument_server_url}{url_path_for('api.router', 'flush_skipped_rsyncer', session_id=session_id)}", |
521 | 546 | json={ |
|
0 commit comments