api_config.py 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. import os
  2. from dataclasses import dataclass
  3. from depth_common import Settings
  4. @dataclass(frozen=True)
  5. class ApiConfig:
  6. sample_count: int
  7. frame_timeout_ms: int
  8. sample_timeout_sec: int
  9. max_saved_images: int
  10. request_log_max_len: int
  11. request_log_max_bytes: int
  12. request_log_backup_count: int
  13. api_host: str
  14. api_port: int
  15. settings: Settings
  16. @classmethod
  17. def from_env(cls) -> "ApiConfig":
  18. return cls(
  19. sample_count=int(os.getenv("SAMPLE_COUNT", "10")),
  20. frame_timeout_ms=int(os.getenv("FRAME_TIMEOUT_MS", "200")),
  21. sample_timeout_sec=int(os.getenv("SAMPLE_TIMEOUT_SEC", "8")),
  22. max_saved_images=int(os.getenv("MAX_SAVED_IMAGES", "1000")),
  23. request_log_max_len=int(os.getenv("REQUEST_LOG_MAX_LEN", "1000")),
  24. request_log_max_bytes=int(os.getenv("REQUEST_LOG_MAX_BYTES", str(20 * 1024 * 1024))),
  25. request_log_backup_count=int(os.getenv("REQUEST_LOG_BACKUP_COUNT", "10")),
  26. api_host=os.getenv("API_HOST", "127.0.0.1"),
  27. api_port=int(os.getenv("API_PORT", "8080")),
  28. settings=Settings.from_env(),
  29. )