diff --git a/docker-compose.yml b/docker-compose.yml index ebc712b..48c7b30 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -39,6 +39,7 @@ services: environment: - DATA_DIR=/data - API_URL=http://app:8000 + - SEED_ADMIN_EMAIL=${SEED_ADMIN_EMAIL:-} depends_on: app: condition: service_healthy @@ -58,5 +59,47 @@ services: - full restart: unless-stopped + ws-gateway: + build: . + command: python -m services.ws_gateway + volumes: + - data:/data + env_file: .env + environment: + - DATA_DIR=/data + depends_on: + - app + profiles: + - full + restart: unless-stopped + + corporate-memory: + build: . + command: python -m services.corporate_memory + volumes: + - data:/data + env_file: .env + environment: + - DATA_DIR=/data + depends_on: + - app + profiles: + - full + restart: unless-stopped + + session-collector: + build: . + command: python -m services.session_collector + volumes: + - data:/data + env_file: .env + environment: + - DATA_DIR=/data + depends_on: + - app + profiles: + - full + restart: unless-stopped + volumes: data: diff --git a/services/scheduler/__main__.py b/services/scheduler/__main__.py index 800b866..98ebb14 100644 --- a/services/scheduler/__main__.py +++ b/services/scheduler/__main__.py @@ -24,6 +24,29 @@ logger = logging.getLogger(__name__) API_URL = os.environ.get("API_URL", "http://localhost:8000") SCHEDULER_API_TOKEN = os.environ.get("SCHEDULER_API_TOKEN", "") +_cached_token = "" + +def _get_auth_token() -> str: + """Get auth token — use SCHEDULER_API_TOKEN or auto-fetch from API.""" + global _cached_token + if SCHEDULER_API_TOKEN: + return SCHEDULER_API_TOKEN + if _cached_token: + return _cached_token + admin_email = os.environ.get("SEED_ADMIN_EMAIL", "") + if not admin_email: + logger.warning("No SCHEDULER_API_TOKEN or SEED_ADMIN_EMAIL — calls will be unauthenticated") + return "" + try: + resp = httpx.post(f"{API_URL}/auth/token", json={"email": admin_email}, timeout=10) + if resp.status_code == 200: + _cached_token = resp.json().get("access_token", "") + logger.info("Auto-fetched scheduler token for %s", admin_email) + return _cached_token + except Exception as e: + logger.warning("Failed to fetch scheduler token: %s", e) + return "" + # Schedule definitions: (name, interval_seconds, api_endpoint, http_method) JOBS = [ ("data-refresh", 15 * 60, "/api/sync/trigger", "POST"), @@ -43,8 +66,9 @@ def _call_api(endpoint: str, method: str = "POST") -> bool: """Call the main app API. Returns True on success.""" url = f"{API_URL}{endpoint}" headers = {} - if SCHEDULER_API_TOKEN: - headers["Authorization"] = f"Bearer {SCHEDULER_API_TOKEN}" + token = _get_auth_token() + if token: + headers["Authorization"] = f"Bearer {token}" try: if method == "POST": resp = httpx.post(url, headers=headers, timeout=120)