初始化
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
from .settings import Settings
|
||||
|
||||
_env = os.getenv("ENV", "dev")
|
||||
_env_files = {"dev": ".env", "test": ".env.test", "prod": ".env.prod"}
|
||||
|
||||
# 定位项目根目录(config 上两级)
|
||||
_project_root = Path(__file__).resolve().parent.parent.parent
|
||||
_env_file = _project_root / _env_files.get(_env, ".env")
|
||||
|
||||
if not _env_file.exists():
|
||||
raise FileNotFoundError(f".env 文件不存在: {_env_file}")
|
||||
|
||||
settings = Settings(_env_file=str(_env_file))
|
||||
|
||||
__all__ = ["settings"]
|
||||
@@ -0,0 +1,70 @@
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
"""项目配置,通过 .env 文件覆盖默认值"""
|
||||
|
||||
# 环境
|
||||
env: str = "dev"
|
||||
|
||||
# ──────────── PostgreSQL(本地,app_job_data 源库)────────────
|
||||
pg_host: str = "192.168.31.51"
|
||||
pg_port: int = 5432
|
||||
pg_user: str = "postgres"
|
||||
pg_password: str = ""
|
||||
pg_db: str = "postgres"
|
||||
pg_pool_size: int = 10
|
||||
pg_max_overflow: int = 20
|
||||
|
||||
# ──────────── MySQL(业务库)────────────
|
||||
db_host: str = "192.168.31.105"
|
||||
db_port: int = 3306
|
||||
db_user: str = "root"
|
||||
db_password: str = "123456"
|
||||
db_name: str = "offerpie"
|
||||
mysql_pool_size: int = 10
|
||||
mysql_max_overflow: int = 20
|
||||
|
||||
# ──────────── AI 供应商 ────────────
|
||||
volcengine_api_key: str = "fd065993-bee2-4f31-8bf2-56d5d3012c02"
|
||||
volcengine_base_url: str = "https://ark.cn-beijing.volces.com/api/v3"
|
||||
|
||||
# ──────────── 岗位清洗参数 ────────────
|
||||
clean_batch_size: int = 100
|
||||
clean_concurrency: int = 50
|
||||
clean_interval_seconds: int = 180
|
||||
|
||||
# ──────────── 公司补充参数 ────────────
|
||||
company_batch_size: int = 20
|
||||
company_concurrency: int = 10
|
||||
company_interval_seconds: int = 300
|
||||
|
||||
# ──────────── 岗位下架参数 ────────────
|
||||
job_expire_days: int = 7
|
||||
|
||||
# ──────────── 日志 ────────────
|
||||
logging_level: str = "INFO"
|
||||
log_file_name: str = "cleaner.log"
|
||||
|
||||
@property
|
||||
def pg_url(self) -> str:
|
||||
from urllib.parse import quote
|
||||
return (
|
||||
f"postgresql+asyncpg://{self.pg_user}:{quote(self.pg_password, safe='')}"
|
||||
f"@{self.pg_host}:{self.pg_port}/{self.pg_db}"
|
||||
)
|
||||
|
||||
@property
|
||||
def mysql_url(self) -> str:
|
||||
from urllib.parse import quote
|
||||
return (
|
||||
f"mysql+asyncmy://{self.db_user}:{quote(self.db_password, safe='')}"
|
||||
f"@{self.db_host}:{self.db_port}/{self.db_name}"
|
||||
)
|
||||
|
||||
model_config = SettingsConfigDict(
|
||||
env_file=".env",
|
||||
env_file_encoding="utf-8",
|
||||
case_sensitive=False,
|
||||
extra="ignore",
|
||||
)
|
||||
Reference in New Issue
Block a user