From 16dcefdfd10e473291cb0a2eb26ebffb6d2f1b6e Mon Sep 17 00:00:00 2001 From: Vladimir Garanin Date: Wed, 11 Feb 2026 09:04:36 +0000 Subject: [PATCH] #311 add a new env var and base live data path on it --- plotting-service/plotting_service/routers/live_data.py | 5 +++-- .../plotting_service/services/live_data_service.py | 6 +++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/plotting-service/plotting_service/routers/live_data.py b/plotting-service/plotting_service/routers/live_data.py index 48cea6c..3cb1087 100644 --- a/plotting-service/plotting_service/routers/live_data.py +++ b/plotting-service/plotting_service/routers/live_data.py @@ -15,6 +15,7 @@ LiveDataRouter = APIRouter(prefix="/live") CEPH_DIR = os.environ.get("CEPH_DIR", "/ceph") +GENERIC_DIR = "GENERIC" if os.environ.get("PRODUCTION", "").lower() == "true" else "GENERIC-staging" stdout_handler = logging.StreamHandler(stream=sys.stdout) logging.basicConfig( @@ -42,7 +43,7 @@ async def get_live_data_files(instrument: str) -> list[str]: status_code=HTTPStatus.NOT_FOUND, detail=f"Live data directory for '{instrument}' not found" ) - safe_check_filepath(live_data_path, CEPH_DIR + "/GENERIC/livereduce") + safe_check_filepath(live_data_path, CEPH_DIR + f"/{GENERIC_DIR}/livereduce") files = [f.name for f in live_data_path.iterdir() if f.is_file()] return sorted(files) @@ -71,7 +72,7 @@ async def live_data(instrument: str, poll_interval: int = 2, keepalive_interval: status_code=HTTPStatus.NOT_FOUND, detail=f"Live data directory for '{instrument}' not found" ) - safe_check_filepath(live_data_path, CEPH_DIR + "/GENERIC/livereduce") + safe_check_filepath(live_data_path, CEPH_DIR + f"/{GENERIC_DIR}/livereduce") return StreamingResponse( generate_file_change_events(live_data_path, CEPH_DIR, instrument, keepalive_interval, poll_interval), diff --git a/plotting-service/plotting_service/services/live_data_service.py b/plotting-service/plotting_service/services/live_data_service.py index 6b7c9dd..b33d385 100644 --- a/plotting-service/plotting_service/services/live_data_service.py +++ b/plotting-service/plotting_service/services/live_data_service.py @@ -3,11 +3,14 @@ import asyncio import contextlib import logging +import os import typing from pathlib import Path logger = logging.getLogger(__name__) +PRODUCTION = os.environ.get("PRODUCTION", "False").lower() == "true" + def get_file_snapshot(directory: Path) -> dict[str, float]: """Get a snapshot of all files in a directory with their modification times. @@ -108,7 +111,8 @@ def get_live_data_directory(instrument: str, ceph_dir: str) -> Path | None: :return: Path to live data directory, or None if it doesn't exist """ instrument_upper = instrument.upper() - live_data_path = Path(ceph_dir) / "GENERIC" / "livereduce" / instrument_upper + generic_dir = "GENERIC" if PRODUCTION else "GENERIC-staging" + live_data_path = Path(ceph_dir) / generic_dir / "livereduce" / instrument_upper if not (live_data_path.exists() and live_data_path.is_dir()): return None