NestJS (6 services): implement @RequirePermission decorator with SetMetadata+Reflector, register APP_GUARD globally, fix as assertions to type guards, add explicit return types, fix import type for express, fix /metrics implicit any, replace native Error with ApplicationError, remove typeorm remnants, register LifecycleService. teacher-bff: add logger, ApplicationError, GlobalErrorFilter, forward real userId to downstream, log downstream failures, migrate health controller to shared/health. Go (2 services): interface to any, doc comments, CORS dev whitelist, JWT secret fail-fast, push-gateway internal API auth, metrics and readyz endpoints, remove dead code. Python (2 services): lifespan return type, dev_mode to bool, data-ana APIRouter, ai POST body model, ClickHouse async wrapping.
47 lines
1.5 KiB
Python
47 lines
1.5 KiB
Python
"""配置管理."""
|
||
|
||
from pydantic_settings import BaseSettings
|
||
|
||
|
||
class Settings(BaseSettings):
|
||
"""应用配置.
|
||
|
||
ClickHouse 连接参数为可选:当 clickhouse_host 为空字符串时,
|
||
服务进入降级模式(查询方法返回 None / 空数据),保证服务可启动。
|
||
|
||
Kafka 连接参数为可选:当 kafka_brokers 为空字符串时,
|
||
CDC 消费者不启动(降级模式),保证服务可启动。
|
||
"""
|
||
|
||
port: int = 3006
|
||
# ClickHouse 连接(可选:留空则降级模式)
|
||
clickhouse_host: str = ""
|
||
clickhouse_port: int = 8123
|
||
clickhouse_database: str = "edu_analytics"
|
||
clickhouse_user: str = ""
|
||
clickhouse_password: str = ""
|
||
# 可观测性
|
||
otel_endpoint: str = "http://localhost:4318"
|
||
log_level: str = "info"
|
||
# 开发模式开关
|
||
dev_mode: bool = False
|
||
# Kafka brokers(CDC 消费;留空则不启动消费者)
|
||
# 主机访问用 localhost:9092,容器内访问用 kafka:29092
|
||
kafka_brokers: str = ""
|
||
# CDC 消费组 id
|
||
kafka_group_id: str = "data-ana-cdc-consumer"
|
||
# 要消费的 CDC topic(Debezium 默认命名:<prefix>.<database>.<table>)
|
||
# 用逗号分隔多个 topic
|
||
kafka_cdc_topics: str = (
|
||
"edu-cdc.next_edu_cloud.core_edu_grades,"
|
||
"edu-cdc.next_edu_cloud.core_edu_exams,"
|
||
"edu-cdc.next_edu_cloud.classes"
|
||
)
|
||
# 消费者自动偏移重置策略(earliest / latest)
|
||
kafka_auto_offset_reset: str = "earliest"
|
||
|
||
model_config = {"env_file": ".env", "env_prefix": ""}
|
||
|
||
|
||
settings = Settings()
|