"""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()