config.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 = 3600
  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. # 次源 dwd_demand_pool_di 同步开关;false 时仅同步主源 dwd_multi_demand_pool_di
  22. demand_pool_secondary_sync_enabled: bool = False
  23. demand_pool_secondary_strategy: str = "近期需求"
  24. demand_pool_secondary_default_ext_info: str = "{}"
  25. demand_pool_target_table: str = "multi_demand_pool_di"
  26. demand_pool_initial_partitions: str = "20260507,20260508,20260509"
  27. demand_pool_hourly_sync_enabled: bool = True
  28. demand_pool_hourly_sync_minute: int = 0
  29. demand_pool_daily_strategy_alert_enabled: bool = True
  30. demand_pool_daily_strategy_alert_hour: int = 10
  31. demand_pool_daily_strategy_alert_minute: int = 0
  32. feishu_webhook_url: str = ""
  33. feishu_webhook_timeout_seconds: int = 30
  34. # 默认不校验 HTTPS 证书,避免公司代理自签链导致发不出消息;生产若需严格校验可设为 true
  35. feishu_webhook_verify_ssl: bool = False
  36. model_config = SettingsConfigDict(
  37. env_file=".env",
  38. env_file_encoding="utf-8",
  39. extra="ignore",
  40. )
  41. @property
  42. def mysql_dsn(self) -> str:
  43. return (
  44. "mysql+pymysql://"
  45. f"{quote_plus(self.mysql_user)}:{quote_plus(self.mysql_password)}"
  46. f"@{self.mysql_host}:{self.mysql_port}/{quote_plus(self.mysql_database)}"
  47. )
  48. @property
  49. def demand_pool_initial_partition_list(self) -> list[str]:
  50. return [
  51. partition.strip()
  52. for partition in self.demand_pool_initial_partitions.split(",")
  53. if partition.strip()
  54. ]
  55. @property
  56. def cors_allow_origin_list(self) -> list[str]:
  57. if self.cors_allow_origins.strip() == "*":
  58. return ["*"]
  59. return [
  60. origin.strip()
  61. for origin in self.cors_allow_origins.split(",")
  62. if origin.strip()
  63. ]
  64. settings = Settings()