Skip to content

Commit 16dcefd

Browse files
committed
#311 add a new env var and base live data path on it
1 parent 27e52e3 commit 16dcefd

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

plotting-service/plotting_service/routers/live_data.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
LiveDataRouter = APIRouter(prefix="/live")
1616

1717
CEPH_DIR = os.environ.get("CEPH_DIR", "/ceph")
18+
GENERIC_DIR = "GENERIC" if os.environ.get("PRODUCTION", "").lower() == "true" else "GENERIC-staging"
1819

1920
stdout_handler = logging.StreamHandler(stream=sys.stdout)
2021
logging.basicConfig(
@@ -42,7 +43,7 @@ async def get_live_data_files(instrument: str) -> list[str]:
4243
status_code=HTTPStatus.NOT_FOUND, detail=f"Live data directory for '{instrument}' not found"
4344
)
4445

45-
safe_check_filepath(live_data_path, CEPH_DIR + "/GENERIC/livereduce")
46+
safe_check_filepath(live_data_path, CEPH_DIR + f"/{GENERIC_DIR}/livereduce")
4647

4748
files = [f.name for f in live_data_path.iterdir() if f.is_file()]
4849
return sorted(files)
@@ -71,7 +72,7 @@ async def live_data(instrument: str, poll_interval: int = 2, keepalive_interval:
7172
status_code=HTTPStatus.NOT_FOUND, detail=f"Live data directory for '{instrument}' not found"
7273
)
7374

74-
safe_check_filepath(live_data_path, CEPH_DIR + "/GENERIC/livereduce")
75+
safe_check_filepath(live_data_path, CEPH_DIR + f"/{GENERIC_DIR}/livereduce")
7576

7677
return StreamingResponse(
7778
generate_file_change_events(live_data_path, CEPH_DIR, instrument, keepalive_interval, poll_interval),

plotting-service/plotting_service/services/live_data_service.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
import asyncio
44
import contextlib
55
import logging
6+
import os
67
import typing
78
from pathlib import Path
89

910
logger = logging.getLogger(__name__)
1011

12+
PRODUCTION = os.environ.get("PRODUCTION", "False").lower() == "true"
13+
1114

1215
def get_file_snapshot(directory: Path) -> dict[str, float]:
1316
"""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:
108111
:return: Path to live data directory, or None if it doesn't exist
109112
"""
110113
instrument_upper = instrument.upper()
111-
live_data_path = Path(ceph_dir) / "GENERIC" / "livereduce" / instrument_upper
114+
generic_dir = "GENERIC" if PRODUCTION else "GENERIC-staging"
115+
live_data_path = Path(ceph_dir) / generic_dir / "livereduce" / instrument_upper
112116

113117
if not (live_data_path.exists() and live_data_path.is_dir()):
114118
return None

0 commit comments

Comments
 (0)