config.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. from urllib.parse import quote_plus
  2. from pydantic_settings import BaseSettings, SettingsConfigDict
  3. class Settings(BaseSettings):
  4. app_name: str = "denamd-server"
  5. app_env: str = "dev"
  6. app_host: str = "0.0.0.0"
  7. app_port: int = 8000
  8. cors_allow_origins: str = "*"
  9. scheduler_heartbeat_seconds: int = 30
  10. mysql_host: str = ""
  11. mysql_port: int = 3306
  12. mysql_user: str = "root"
  13. mysql_password: str = ""
  14. mysql_database: str = ""
  15. odps_access_id: str = "LTAI9EBa0bd5PrDa"
  16. odps_access_key: str = "vAalxds7YxhfOA2yVv8GziCg3Y87v5"
  17. odps_project: str = "loghubods"
  18. odps_endpoint: str = "http://service.odps.aliyun.com/api"
  19. demand_pool_source_table: str = "dwd_multi_demand_pool_di"
  20. demand_pool_secondary_source_table: str = "dwd_demand_pool_di"
  21. demand_pool_secondary_strategy: str = "近期需求"
  22. demand_pool_secondary_default_ext_info: str = "{}"
  23. demand_pool_target_table: str = "multi_demand_pool_di"
  24. demand_pool_initial_partitions: str = "20260507,20260508,20260509"
  25. demand_pool_hourly_sync_enabled: bool = True
  26. demand_pool_hourly_sync_minute: int = 0
  27. model_config = SettingsConfigDict(
  28. env_file=".env",
  29. env_file_encoding="utf-8",
  30. extra="ignore",
  31. )
  32. @property
  33. def mysql_dsn(self) -> str:
  34. return (
  35. "mysql+pymysql://"
  36. f"{quote_plus(self.mysql_user)}:{quote_plus(self.mysql_password)}"
  37. f"@{self.mysql_host}:{self.mysql_port}/{quote_plus(self.mysql_database)}"
  38. )
  39. @property
  40. def demand_pool_initial_partition_list(self) -> list[str]:
  41. return [
  42. partition.strip()
  43. for partition in self.demand_pool_initial_partitions.split(",")
  44. if partition.strip()
  45. ]
  46. @property
  47. def cors_allow_origin_list(self) -> list[str]:
  48. if self.cors_allow_origins.strip() == "*":
  49. return ["*"]
  50. return [
  51. origin.strip()
  52. for origin in self.cors_allow_origins.split(",")
  53. if origin.strip()
  54. ]
  55. settings = Settings()