69 lines
No EOL
2.3 KiB
Python
69 lines
No EOL
2.3 KiB
Python
import os
|
|
from datetime import timedelta
|
|
|
|
|
|
class Config:
|
|
"""Base configuration"""
|
|
SECRET_KEY = os.environ.get('SECRET_KEY') or 'dev-secret-key-change-in-production'
|
|
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
|
JWT_SECRET_KEY = os.environ.get('JWT_SECRET_KEY') or 'jwt-secret-key-change-in-production'
|
|
JWT_ACCESS_TOKEN_EXPIRES = timedelta(hours=1)
|
|
JWT_REFRESH_TOKEN_EXPIRES = timedelta(days=30)
|
|
|
|
# Celery Configuration
|
|
CELERY = {
|
|
"broker_url": os.environ.get("CELERY_BROKER_URL", "redis://localhost:6379/0"),
|
|
"result_backend": os.environ.get("CELERY_RESULT_BACKEND", "redis://localhost:6379/0"),
|
|
"task_serializer": "json",
|
|
"result_serializer": "json",
|
|
"accept_content": ["json"],
|
|
"timezone": "UTC",
|
|
"enable_utc": True,
|
|
"task_track_started": True,
|
|
"task_time_limit": 30 * 60, # 30 minutes
|
|
"task_soft_time_limit": 25 * 60, # 25 minutes
|
|
"task_acks_late": True, # Acknowledge after task completion
|
|
"task_reject_on_worker_lost": True, # Re-queue if worker dies
|
|
"worker_prefetch_multiplier": 1, # Process one task at a time
|
|
"worker_max_tasks_per_child": 100, # Restart worker after 100 tasks
|
|
"broker_connection_retry_on_startup": True,
|
|
"broker_connection_max_retries": 5,
|
|
"result_expires": 3600, # Results expire in 1 hour
|
|
"task_default_queue": "default",
|
|
"task_default_exchange": "default",
|
|
"task_default_routing_key": "default",
|
|
}
|
|
|
|
|
|
class DevelopmentConfig(Config):
|
|
"""Development configuration"""
|
|
DEBUG = True
|
|
SQLALCHEMY_DATABASE_URI = os.environ.get('DEV_DATABASE_URL') or \
|
|
'sqlite:///dev.db'
|
|
|
|
|
|
class TestingConfig(Config):
|
|
"""Testing configuration"""
|
|
TESTING = True
|
|
SQLALCHEMY_DATABASE_URI = os.environ.get('TEST_DATABASE_URL') or \
|
|
'sqlite:///test.db'
|
|
WTF_CSRF_ENABLED = False
|
|
|
|
|
|
class ProductionConfig(Config):
|
|
"""Production configuration"""
|
|
DEBUG = False
|
|
SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL') or \
|
|
'postgresql://user:password@localhost/proddb'
|
|
|
|
# Security headers
|
|
SESSION_COOKIE_SECURE = True
|
|
SESSION_COOKIE_HTTPONLY = True
|
|
SESSION_COOKIE_SAMESITE = 'Lax'
|
|
|
|
|
|
config_by_name = {
|
|
'dev': DevelopmentConfig,
|
|
'test': TestingConfig,
|
|
'prod': ProductionConfig
|
|
} |