Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions plotting-service/plotting_service/routers/live_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down