Files
ai-talk-callback/app/config.py
2025-12-10 08:19:04 +08:00

68 lines
2.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from pydantic_settings import BaseSettings
class Settings(BaseSettings):
@property
def redis_url(self) -> str:
"""从Celery配置获取Redis URL"""
return self.celery_broker_url
# 数据库配置
database_url: str = ""
# Celery配置
celery_broker_url: str = "redis://localhost:6379/0"
celery_result_backend: str = "redis://localhost:6379/1"
celery_task_serializer: str = "json"
celery_result_serializer: str = "json"
celery_accept_content: list = ["json"]
celery_timezone: str = "Asia/Shanghai"
celery_enable_utc: bool = False
# 任务配置
enabled_push_data_to_dtc_task: bool = False # 是否启用推送数据给DTC的任务
enabled_call_api_task: bool = False # 是否启用调用API的任务
# Flower监控配置
flower_enabled: bool = True # 是否启用Flower监控
flower_url: str = "http://localhost:5555" # Flower访问URL
flower_port: int = 5555 # Flower服务端口
flower_url_prefix: str = "" # Flower URL前缀
flower_basic_auth: str = "admin:admin123" # Flower基础认证,格式:username:password
# Redis配置 (从Celery配置获取)
redis_password: str = ""
redis_max_connections: int = 20
redis_timeout: int = 5
# 业务配置
count_threshold: int = 3 # count阈值,大于等于此值直接返回
external_api_enabled: bool = False # 是否启用外部API调用
external_api_retry_max: int = 3 # 外部API最大重试次数
external_api_url: str = ""
# Redis锁配置 (使用默认值)
redis_lock_timeout: int = 300 # 锁超时时间(秒)
redis_lock_max_retries: int = 10 # 最大重试次数
redis_lock_retry_delay: float = 0.5 # 重试延迟(秒)
# 日志配置
log_level: str = "INFO" # DEBUG, INFO, WARNING, ERROR, CRITICAL
log_file: str = "logs/app.log" # 日志文件路径
log_max_bytes: int = 10 * 1024 * 1024 # 10MB
log_backup_count: int = 5 # 备份文件数量
log_format: str = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
log_date_format: str = "%Y-%m-%d %H:%M:%S"
# 应用配置
app_name: str = "AI Talk Callback API"
environment: str = "production" # 环境: production, test, development
debug: bool = False
disable_docs: bool = False
class Config:
env_file = ".env"
case_sensitive = False
settings = Settings()