forked from mtusi2026/mtusi2026lab2
32 lines
1.0 KiB
Python
32 lines
1.0 KiB
Python
from pathlib import Path
|
|
|
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
model_config = SettingsConfigDict(env_file='.env', extra='ignore')
|
|
|
|
app_host: str = '0.0.0.0'
|
|
app_port: int = 8080
|
|
session_ttl_seconds: int = 3600
|
|
database_url: str = ''
|
|
database_url_file: str | None = None
|
|
redis_url: str = 'redis://localhost:6379/0'
|
|
redis_url_file: str | None = None
|
|
db_pool_min_size: int = 1
|
|
db_pool_max_size: int = 10
|
|
db_pool_acquire_timeout_seconds: float = 3.0
|
|
db_command_timeout_seconds: float = 5.0
|
|
redis_timeout_seconds: float = 2.0
|
|
|
|
def resolved_database_url(self) -> str:
|
|
if self.database_url_file:
|
|
return Path(self.database_url_file).read_text(encoding='utf-8').strip()
|
|
return self.database_url
|
|
|
|
def resolved_redis_url(self) -> str:
|
|
if self.redis_url_file:
|
|
return Path(self.redis_url_file).read_text(encoding='utf-8').strip()
|
|
return self.redis_url
|
|
settings = Settings()
|