config.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. demand_pool_daily_strategy_alert_enabled: bool = True
  28. demand_pool_daily_strategy_alert_hour: int = 10
  29. demand_pool_daily_strategy_alert_minute: int = 0
  30. feishu_webhook_url: str = ""
  31. feishu_webhook_timeout_seconds: int = 30
  32. # 默认不校验 HTTPS 证书,避免公司代理自签链导致发不出消息;生产若需严格校验可设为 true
  33. feishu_webhook_verify_ssl: bool = False
  34. model_config = SettingsConfigDict(
  35. env_file=".env",
  36. env_file_encoding="utf-8",
  37. extra="ignore",
  38. )
  39. @property
  40. def mysql_dsn(self) -> str:
  41. return (
  42. "mysql+pymysql://"
  43. f"{quote_plus(self.mysql_user)}:{quote_plus(self.mysql_password)}"
  44. f"@{self.mysql_host}:{self.mysql_port}/{quote_plus(self.mysql_database)}"
  45. )
  46. @property
  47. def demand_pool_initial_partition_list(self) -> list[str]:
  48. return [
  49. partition.strip()
  50. for partition in self.demand_pool_initial_partitions.split(",")
  51. if partition.strip()
  52. ]
  53. @property
  54. def cors_allow_origin_list(self) -> list[str]:
  55. if self.cors_allow_origins.strip() == "*":
  56. return ["*"]
  57. return [
  58. origin.strip()
  59. for origin in self.cors_allow_origins.split(",")
  60. if origin.strip()
  61. ]
  62. settings = Settings()