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
2 changes: 0 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,5 @@ OIDC_AUDIENCES=
# --- Cache process management ----------------------------------------------
# Path to the fastcache executable; bare name = resolved via PATH.
FASTCACHE_BINARY=lclstream-fastcache
# Directory where per-cache config/log files are written.
RUN_DIR=run
# Grace period (seconds) before escalating SIGTERM to SIGKILL on shutdown.
SHUTDOWN_GRACE_SECONDS=5.0
2 changes: 0 additions & 2 deletions src/fastcache_api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ class Settings(BaseSettings):
# Cache process management
# Path to the fastcache executable (overridable; defaults to PATH lookup).
FASTCACHE_BINARY: Path = Path("lclstream-fastcache")
# Directory where per-cache config/log files are written.
RUN_DIR: Path = Path("run")
# Grace period before escalating SIGTERM to SIGKILL on shutdown.
SHUTDOWN_GRACE_SECONDS: float = 5.0
# How often the liveness poller checks running caches against their pids.
Expand Down
2 changes: 2 additions & 0 deletions src/fastcache_api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class CacheRequest(BaseModel):
# Human who initiated the transfer upstream (bearer token is a shared
# service identity, so attribution must travel in the request body).
requested_by: str
# Absolute path the orchestrator dictates for this cache's log.
log_path: Path


class CachePublic(BaseModel):
Expand Down
8 changes: 5 additions & 3 deletions src/fastcache_api/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import socket
import subprocess
from collections.abc import Iterable
from pathlib import Path
from uuid import UUID

import psutil
Expand Down Expand Up @@ -35,17 +36,18 @@ def allocate_port_pair(in_use: set[int], start: int, end: int) -> tuple[int, int
raise RuntimeError(f"no free cache port pair in range [{start}, {end}]")


def start_cache(cache_id: UUID, config: CacheConfig) -> CacheProcess:
run_dir = settings.RUN_DIR / str(cache_id)
def start_cache(cache_id: UUID, config: CacheConfig, log_path: Path) -> CacheProcess:
run_dir = log_path.parent
run_dir.mkdir(parents=True, exist_ok=True)

config_path = run_dir / "config.json"
config_path.write_text(config.to_fastcache_json())

log_path = (run_dir / "cache.log").resolve()
log_path = log_path.resolve()
with log_path.open("ab") as log_file:
proc = subprocess.Popen(
[settings.FASTCACHE_BINARY, config_path],
cwd=run_dir,
stdout=log_file,
stderr=subprocess.STDOUT,
start_new_session=True,
Expand Down
2 changes: 1 addition & 1 deletion src/fastcache_api/routes/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ async def create_cache(

cache_id = uuid4()
try:
proc = start_cache(cache_id, config)
proc = start_cache(cache_id, config, req.log_path)
except (FileNotFoundError, OSError, RuntimeError) as exc:
raise HTTPException(
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
Expand Down