Files
bttoxin-pipeline/web/backend/config.py
hotwa 4c9a7d0978 docs: 添加中文文档,新增前端和后端代码
- 新增 README_CN.md 中文文档
- 新增 frontend/ Vue 3 前端项目
- 新增 web/ FastAPI 后端项目

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-08 22:31:06 +08:00

78 lines
2.5 KiB
Python

"""Configuration module for BtToxin Pipeline Web Backend.
Defines System Constraints and environment variable configuration.
Requirements: 7.5
"""
import os
from dataclasses import dataclass
from typing import List
@dataclass(frozen=True)
class SystemConstraints:
"""System constraints and limits for the BtToxin Pipeline Web application."""
# Upload and storage limits
MAX_UPLOAD_SIZE: int = 50 * 1024 * 1024 # 50 MB
MIN_FREE_DISK_GB: int = 20 # Minimum free disk space in GB
MAX_TOTAL_STORAGE_GB: int = 500 # Maximum total storage in GB
# Task execution limits
TASK_TIMEOUT: int = 6 * 60 * 60 # 6 hours in seconds (21600)
TASK_THREADS: int = 4 # Default threads per task
# Concurrency and queue limits
WORKER_CONCURRENCY: int = 32 # Celery worker process concurrency
MAX_ACTIVE_PIPELINES: int = 4 # Max concurrent Digger containers
QUEUE_MAX_LENGTH: int = 1000 # Maximum queue length
# Data retention
RESULT_RETENTION_DAYS: int = 30 # Results kept for 30 days
# Allowed file extensions
ALLOWED_EXTENSIONS: tuple = (".fna", ".fa", ".fasta")
# Valid nucleotide characters (uppercase and lowercase)
VALID_NUCLEOTIDES: frozenset = frozenset("ATGCNatgcn")
class Settings:
"""Application settings loaded from environment variables."""
def __init__(self):
# Redis configuration
self.redis_url: str = os.getenv("REDIS_URL", "redis://localhost:6379/0")
# Jobs directory
self.jobs_dir: str = os.getenv("JOBS_DIR", "/data/jobs")
# Task execution settings (can override SystemConstraints defaults)
self.task_timeout: int = int(
os.getenv("TASK_TIMEOUT", str(SystemConstraints.TASK_TIMEOUT))
)
self.max_active_pipelines: int = int(
os.getenv("MAX_ACTIVE_PIPELINES", str(SystemConstraints.MAX_ACTIVE_PIPELINES))
)
self.task_threads: int = int(
os.getenv("TASK_THREADS", str(SystemConstraints.TASK_THREADS))
)
self.worker_concurrency: int = int(
os.getenv("WORKER_CONCURRENCY", str(SystemConstraints.WORKER_CONCURRENCY))
)
# CORS settings
self.cors_origins: List[str] = os.getenv(
"CORS_ORIGINS", "*"
).split(",")
# API settings
self.api_prefix: str = "/api/v1"
self.debug: bool = os.getenv("DEBUG", "false").lower() == "true"
# Global settings instance
settings = Settings()
# Global constraints instance
constraints = SystemConstraints()