mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-12 22:42:13 +02:00
refactor(config): centralize configuration management across modules
- Replaced environment variable usage with a centralized configuration system in multiple modules, including `celery_app`, `agent_cache_store`, `sandbox`, `file_storage`, and `connector_service`. - Enhanced maintainability and readability by sourcing configuration values from the `config` module instead of directly from environment variables. - Updated relevant settings to ensure consistent access to configuration values across the application.
This commit is contained in:
parent
ef7a20a5d0
commit
c2beaf1e5a
6 changed files with 176 additions and 123 deletions
|
|
@ -67,13 +67,13 @@ from __future__ import annotations
|
|||
import asyncio
|
||||
import hashlib
|
||||
import logging
|
||||
import os
|
||||
import time
|
||||
from collections import OrderedDict
|
||||
from collections.abc import Awaitable, Callable
|
||||
from dataclasses import dataclass
|
||||
from typing import Any
|
||||
|
||||
from app.config import config
|
||||
from app.utils.perf import get_perf_logger
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
|
@ -328,8 +328,8 @@ def _short(key: str, n: int = 16) -> str:
|
|||
# Module-level singleton
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
_DEFAULT_MAXSIZE = int(os.getenv("SURFSENSE_AGENT_CACHE_MAXSIZE", "256"))
|
||||
_DEFAULT_TTL = float(os.getenv("SURFSENSE_AGENT_CACHE_TTL_SECONDS", "1800"))
|
||||
_DEFAULT_MAXSIZE = config.AGENT_CACHE_MAXSIZE
|
||||
_DEFAULT_TTL = config.AGENT_CACHE_TTL_SECONDS
|
||||
|
||||
_cache: _AgentCache = _AgentCache(maxsize=_DEFAULT_MAXSIZE, ttl_seconds=_DEFAULT_TTL)
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ from __future__ import annotations
|
|||
import asyncio
|
||||
import contextlib
|
||||
import logging
|
||||
import os
|
||||
import shutil
|
||||
import threading
|
||||
from pathlib import Path
|
||||
|
|
@ -29,6 +28,10 @@ from daytona.common.errors import DaytonaError
|
|||
from deepagents.backends.protocol import ExecuteResponse
|
||||
from langchain_daytona import DaytonaSandbox
|
||||
|
||||
# Aliased to avoid clashing with the local ``config = DaytonaConfig(...)``
|
||||
# variable used inside ``_get_client``.
|
||||
from app.config import config as app_config
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
|
@ -73,7 +76,7 @@ SANDBOX_DOCUMENTS_ROOT = "/home/daytona/documents"
|
|||
|
||||
|
||||
def is_sandbox_enabled() -> bool:
|
||||
return os.environ.get("DAYTONA_SANDBOX_ENABLED", "FALSE").upper() == "TRUE"
|
||||
return app_config.DAYTONA_SANDBOX_ENABLED
|
||||
|
||||
|
||||
def _get_client() -> Daytona:
|
||||
|
|
@ -81,9 +84,9 @@ def _get_client() -> Daytona:
|
|||
with _client_lock:
|
||||
if _daytona_client is None:
|
||||
config = DaytonaConfig(
|
||||
api_key=os.environ.get("DAYTONA_API_KEY", ""),
|
||||
api_url=os.environ.get("DAYTONA_API_URL", "https://app.daytona.io/api"),
|
||||
target=os.environ.get("DAYTONA_TARGET", "us"),
|
||||
api_key=app_config.DAYTONA_API_KEY,
|
||||
api_url=app_config.DAYTONA_API_URL,
|
||||
target=app_config.DAYTONA_TARGET,
|
||||
)
|
||||
_daytona_client = Daytona(config)
|
||||
return _daytona_client
|
||||
|
|
@ -92,7 +95,7 @@ def _get_client() -> Daytona:
|
|||
def _sandbox_create_params(
|
||||
labels: dict[str, str],
|
||||
) -> CreateSandboxFromSnapshotParams:
|
||||
snapshot_id = os.environ.get("DAYTONA_SNAPSHOT_ID") or None
|
||||
snapshot_id = app_config.DAYTONA_SNAPSHOT_ID
|
||||
return CreateSandboxFromSnapshotParams(
|
||||
language="python",
|
||||
labels=labels,
|
||||
|
|
@ -302,7 +305,7 @@ async def delete_sandbox(thread_id: int | str) -> None:
|
|||
|
||||
|
||||
def _get_sandbox_files_dir() -> Path:
|
||||
return Path(os.environ.get("SANDBOX_FILES_DIR", "sandbox_files"))
|
||||
return Path(app_config.SANDBOX_FILES_DIR)
|
||||
|
||||
|
||||
def _local_path_for(thread_id: int | str, sandbox_path: str) -> Path:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue