Initial commit - production deployment
This commit is contained in:
1
services/recipes/app/core/__init__.py
Normal file
1
services/recipes/app/core/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
# services/recipes/app/core/__init__.py
|
||||
77
services/recipes/app/core/config.py
Normal file
77
services/recipes/app/core/config.py
Normal file
@@ -0,0 +1,77 @@
|
||||
# services/recipes/app/core/config.py
|
||||
"""
|
||||
Configuration management for Recipe Service
|
||||
"""
|
||||
|
||||
import os
|
||||
from typing import Optional
|
||||
from shared.config.base import BaseServiceSettings
|
||||
|
||||
|
||||
class Settings(BaseServiceSettings):
|
||||
"""Recipe service configuration extending base configuration"""
|
||||
|
||||
# Override service-specific settings
|
||||
SERVICE_NAME: str = "recipes-service"
|
||||
VERSION: str = "1.0.0"
|
||||
APP_NAME: str = "Recipe Service"
|
||||
DESCRIPTION: str = "Recipe management and planning service"
|
||||
|
||||
# API Configuration
|
||||
API_V1_STR: str = "/api/v1"
|
||||
|
||||
# Database configuration (secure approach - build from components)
|
||||
@property
|
||||
def DATABASE_URL(self) -> str:
|
||||
"""Build database URL from secure components"""
|
||||
# Try complete URL first (for backward compatibility)
|
||||
complete_url = os.getenv("RECIPES_DATABASE_URL")
|
||||
if complete_url:
|
||||
return complete_url
|
||||
|
||||
# Build from components (secure approach)
|
||||
user = os.getenv("RECIPES_DB_USER", "recipes_user")
|
||||
password = os.getenv("RECIPES_DB_PASSWORD", "recipes_pass123")
|
||||
host = os.getenv("RECIPES_DB_HOST", "localhost")
|
||||
port = os.getenv("RECIPES_DB_PORT", "5432")
|
||||
name = os.getenv("RECIPES_DB_NAME", "recipes_db")
|
||||
|
||||
return f"postgresql+asyncpg://{user}:{password}@{host}:{port}/{name}"
|
||||
|
||||
# Redis configuration - use a specific database number
|
||||
REDIS_DB: int = 2
|
||||
|
||||
# Recipe-specific settings
|
||||
MAX_RECIPE_INGREDIENTS: int = int(os.getenv("MAX_RECIPE_INGREDIENTS", "50"))
|
||||
MAX_BATCH_SIZE_MULTIPLIER: float = float(os.getenv("MAX_BATCH_SIZE_MULTIPLIER", "10.0"))
|
||||
DEFAULT_RECIPE_VERSION: str = "1.0"
|
||||
|
||||
# Production settings (integration with production service)
|
||||
MAX_PRODUCTION_BATCHES_PER_DAY: int = int(os.getenv("MAX_PRODUCTION_BATCHES_PER_DAY", "100"))
|
||||
PRODUCTION_SCHEDULE_DAYS_AHEAD: int = int(os.getenv("PRODUCTION_SCHEDULE_DAYS_AHEAD", "7"))
|
||||
|
||||
# Cost calculation settings
|
||||
OVERHEAD_PERCENTAGE: float = float(os.getenv("OVERHEAD_PERCENTAGE", "15.0")) # Default 15% overhead
|
||||
LABOR_COST_PER_HOUR: float = float(os.getenv("LABOR_COST_PER_HOUR", "25.0")) # Default €25/hour
|
||||
|
||||
# Quality control
|
||||
MIN_QUALITY_SCORE: float = float(os.getenv("MIN_QUALITY_SCORE", "6.0")) # Minimum acceptable quality score
|
||||
MAX_DEFECT_RATE: float = float(os.getenv("MAX_DEFECT_RATE", "5.0")) # Maximum 5% defect rate
|
||||
|
||||
# External service URLs (specific to recipes service)
|
||||
PRODUCTION_SERVICE_URL: str = os.getenv(
|
||||
"PRODUCTION_SERVICE_URL",
|
||||
"http://production-service:8000"
|
||||
)
|
||||
INVENTORY_SERVICE_URL: str = os.getenv(
|
||||
"INVENTORY_SERVICE_URL",
|
||||
"http://inventory-service:8000"
|
||||
)
|
||||
SALES_SERVICE_URL: str = os.getenv(
|
||||
"SALES_SERVICE_URL",
|
||||
"http://sales-service:8000"
|
||||
)
|
||||
|
||||
|
||||
# Global settings instance
|
||||
settings = Settings()
|
||||
25
services/recipes/app/core/database.py
Normal file
25
services/recipes/app/core/database.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# services/recipes/app/core/database.py
|
||||
"""
|
||||
Database configuration and session management for Recipe Service
|
||||
"""
|
||||
|
||||
from shared.database.base import DatabaseManager, create_database_manager
|
||||
from .config import settings
|
||||
|
||||
# Create database manager using shared async infrastructure
|
||||
db_manager = create_database_manager(
|
||||
database_url=settings.DATABASE_URL,
|
||||
service_name="recipes-service",
|
||||
echo=settings.DEBUG
|
||||
)
|
||||
|
||||
# Dependency for FastAPI routes
|
||||
async def get_db():
|
||||
"""FastAPI dependency to get database session"""
|
||||
async for session in db_manager.get_db():
|
||||
yield session
|
||||
|
||||
# Initialize database
|
||||
async def init_database():
|
||||
"""Initialize database tables"""
|
||||
await db_manager.create_tables()
|
||||
Reference in New Issue
Block a user